[Qt-interest] Help! calling a JavaScript function from a Qt object

michael.goddard at nokia.com michael.goddard at nokia.com
Tue Jun 22 08:44:23 CEST 2010


Hello Howard,

> In my Qt object (MyObject) I see the QVariant Q_PROPERTY cbfun is
> actually a QVariantMap of length zero! I need the name or some other
> type of handle to be able to call JavaScript function reverenced by
> cbfun from my Qt object.
> 
> Note that one can easily call the JavaScript function "cb" with
> evaluateJavaScript(), but that requires a priori knowledge of the
> callback function name -- this is not what I need..
> 
> Any ideas how I can get the name of my callback function or any other
> type of handle that would allow me to call it from my Qt object?
> Thanks!

Instead of the property, you could have:

class MyObject : public Qobject {
...
signals:
   void stuffChanged();
};

And in your JS you could do:

MyObject.stuffChanged.connect(cb);

And just emit the stuffChanged signal when you want the callbacks to be called.

(I haven't tried this for a while, though, YMMV :)

Cheers,
MichaelG




More information about the Qt-interest-old mailing list