April 2018
Beginner
714 pages
18h 21m
English
Sometimes you just want to provide a single function instead of an object. Unfortunately, QJSEngine only supports functions that belong to QObject-derived classes. However, we can hide this implementation detail from the JavaScript side. First, create a subclass of QObject and add an invokable member function that proxies the original standalone function:
Q_INVOKABLE double factorial(int x) {
return superFastFactorial(x);
}
Next, expose the wrapper object using the newQObject() function, as usual. However, instead of assigning this object to a property of the global object, extract the factorial property from the object:
QJSValue myObjectJS = engine.newQObject(new MyObject()); engine.globalObject().setProperty("factorial", ...Read now
Unlock full access