[webkit-qt] Nested objects with QtWebKit bridge

noam.rosenthal at nokia.com noam.rosenthal at nokia.com
Wed Aug 24 05:41:21 PDT 2011


You can use a property, but it would have to be of type QObject* or QVariant; There's no smarts to figure out that a QObject subclass should be treated like a QObject.
No'am

On Aug 24, 2011, at 5:36 AM, ext Loïc Yhuel wrote:

> Le mercredi 24 août 2011 13:36:23, Andrew Webster a écrit :
>> 
>> On Wed, Aug 24, 2011 at 6:42 AM, Loïc Yhuel
>> <loic.yhuel_ext at softathome.com> wrote:
>>> 
>>> Hi,
>>> 
>>> I want to define Q_INVOKABLE methods f1 and f2 in C++, which can be 
>>> called
>>> in JS by A.f1() and A.B.f2()
>>> 
>>> As explained in the documentation, I can't add B class as a property 
>>> of A.
>>> The only workaround I found is :
>>> webFrame->addToJavaScriptWindowObject("A", myA);
>>> webFrame->addToJavaScriptWindowObject("_B", myB);
>>> webFrame->evaluateJavaScript("A.B = _B");
>>> 
>>> I there a better way ?
>> 
>> 
>> If you make myA the parent object of myB and give myB the objectName
>> "B", then you should be able to access it from JS using "A.B". When
>> accessing a JS property of a QObject, Q_PROPERTYs and named children
>> get searched for a match.
> Thanks.
> I'm suprised, since it doesn't work with Q_PROPERTY (I have to use to 
> Q_DECLARE_METATYPE/qRegisterMetatype, and then A.B is empty), but using 
> object children and objectName works.
>> 
>> 
>> Andrew
> 
> 
> _______________________________________________
> webkit-qt mailing list
> webkit-qt at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-qt



More information about the webkit-qt mailing list