Q: Howto expose one QObject-inherited object to JS namespace ?
Ian Reinhart Geiser
geiseri at sourcextreme.com
Thu Aug 4 16:17:27 CEST 2005
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.
> 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.
> 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.
> 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
-ian reinhart geiser
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-soc/attachments/20050805/e46eee32/attachment.pgp
More information about the Kde-soc