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

Kun Xi bookstack at gmail.com
Thu Aug 4 20:33:12 CEST 2005


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,
> >
> > Sorry to bother you again. I have spend several hours in googling and
> > digging into the kjsembed source code, tring to figure out how to
> > expose the C++ object to JS namespace.
> No problems what so ever.

Thanks.

> 
> > The background of this question is soc-kde-scripting project. I have
> > exposed the KABCore instance mCore as "Contacts" and I found several
> > interesting things:
> >
> > 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...


> > 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 JS could access Contacts, but complains that the addressBook is
> > unamed( KAB::AddressBook ). It is recoganized inherited from QObject.
> >
> > My question is:  How could I expose mAddressBook ? Should I develop a
> > wrapper class or use JSOpaqueProxy to delegate mAddressBook ? Could
> > you be kind enough to provide some small examples ?
> Hmm, I have to think about this.  In v3 you can "extend" bindings, but I am
> not sure if that part is public.  I am trying to make it suck less in v4, but
> I am not sure where the best route is.  Basicly what happens is you crate the
> QObject version of your bindings, and then add the non-slot methods manually.
> Again this is somewhere I would need to see the current context, but I think
> its possible.  Verbose, and you may decide to hate me afterwords, but
> possible :)

In fact, it is OK. At least, I don't need to care about the security
issues. Only public
slots can be accessed. So, how to manually add methods, using JSObjectProxy ?
George suggests me to take a look at Kst, maybe I would do that and go back to
keep bugging you. :-).

Best regards,

Kun Xi 

> 
> Cheers
>         -ian reinhart geiser
> 
> 
>


More information about the Kde-soc mailing list