Search code examples
qtqmlqt5qt-quickqtquick2

Can QObject be made callable from Java Script


Is it possible to make QObject callable from Java Script? What I mean is to register QObject derived class instance like this:

QObject* obj = new MyObject();
QJSValue js_value = js_engine.newQObject(obj);

js_engine.globalObject().setProperty("myFunction", js_value);

and then to be able to call myFunction from Java Script

myFunction()

Environment: Qt 5.0.1

Edit: Main purpose of this manipulation is to register C++ function or functor in Java Script engine and to make it available not as an object's property but as a standalone function.


Solution

  • I spent too much time trying to do the same. And now I'm 99.9% sure there is no possibility to do that with current Qt build (5.0.1).