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

Ian Reinhart Geiser geiseri at sourcextreme.com
Mon Aug 8 17:43:06 CEST 2005


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.


> > > 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.

Cheers
-ian reinhart geiser
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-soc/attachments/20050808/ab49878d/attachment.pgp


More information about the Kde-soc mailing list