Q: Howto expose one QObject-inherited object to JS namespace ?

Kun Xi bookstack at gmail.com
Mon Aug 8 19:32:20 CEST 2005


On 8/8/05, Ian Reinhart Geiser <geiseri at sourcextreme.com> wrote:
> On Thursday 04 August 2005 02:33 pm, Kun Xi wrote:
> > On 8/4/05, Ian Reinhart Geiser <geiseri at sourcextreme.com> wrote:
> > > On Thursday 04 August 2005 05:47 am, Kun Xi wrote:
> > > > Hello Geiser,
> [...]
> > > > 1) Only public slot function can be accessed even the JSSecurityPolicy
> > > > is set to CapabilityAll. Is this that designed deliberatedly ?
> > >
> > > Yes, this is because the bindings access them without inheritance.  There
> > > currently is no good way to expose non-public slots with the bindings.
> >
> > Wow :-8, I thought the binding would take care of the inheritance. In
> > you bindings
> > implementation, QObject, QPointer, QPixmap ... and all other class that are
> > not inherited from QObjects, are delegated. For the QLabel object, we can
> > access text
> > property, I thought any Qt objects are handled through inheritance...
> QObjects should get all of their superclasse's properties and slots.  For
> non-QObjects you must add them manually.

In fact, not so easy. First, only public slots can be accessed.
Second, a QObject-oriented
class can not be constructed without extra work.

> 
> 
> > > > 2) To access the addressBook in KABCore, I added the following lines
> > > > in KABCore::publishObject() :
> > > > {
> > > > KJSEmbedPart *js = KPIM::KJSEngine::instance();
> > > >
> > > >   JSSecurityPolicy::setDefaultPolicy( JSSecurityPolicy::CapabilityAll
> > > > );
> > > >
> > > >   KJS::Object root = js->addObject(this, "Contacts");
> > > >   js->addObject( mAddressBook, root, "addressBook" );
> > > > }
> > >
> > > There are some stupid problems with namespaces and QObjects currently.
> > > Is this code up somewhere so I could take a look at it?  This is a
> > > "funny" area, and I might need to see more of the context of what is
> > > going on.
> >
> > Sure, the source tree residents in
> > $KDE_SVN/branches/work/soc-kde-scripting, and the above code is snippeted
> > from $SOC-KDE-SCRIPTING/kaddressbook/kabcore.cpp
> The code there looks correct.  The proxy though looks incomplete.  It will
> need a call method implemented to make the sendMail work.  But other than
> that is looks correct.
> 
> I could be missing something though.  If I understand it you are creating an
> object "Contact" and then it will have a "sendMail" method on it.  Can you
> from the javascript console do a:
> var con = new Contact(this); // This is important due to a braindamage on my
> part.
> for( var x in con )
>         print( x );
> 
> This should print "sendMail" out.

I have updated the code. But now, the script could not new a Contact. Since the
Contact is the global object exposed to the script namespace. The code
is supposed
to be (not tested, I am out of my Linux box now ) :
for (var x in Contacts )
   print (x)

sendMail is the only method that should be shown up.  Since now, I 
use a wrapper
class for Contact object to add more access control.



> 
> Cheers
> -ian reinhart geiser
> 
> 
> 

Best regards.

Kun Xi


More information about the Kde-soc mailing list