QJSValue engine() deprecated in Qt5.15
-
Hello,
I am using C++ to interpret some callable QJSValue coming from QML as callback functions.
Currently, i was using the engine() function to add parameters to those function like this:QJsValueList args; args << callable.engine()->toScriptValue(aValue); callcable.call(args);
Now the engine() function is deprecated.
How can i get the callable engine, as if i use an other engine to create the value, it is not possible to use the call(..) function with it? -
I do not have a real answer for that. But I also use QJSValue callbacks a lot, and I think that this is a very important pattern (which is not so well supported by Qt unfortunately).
Im my case, the C++ function is always a method of a QObject exposed to QML (either via singleton or it is instantiated from QML). In both cases, you can get the engine via qjsEngine() on that object:
class App : public QObject { Q_OBJECT Q_INVOKABLE void doSomethingAsync(QJSValue callback) { auto engine = qjsEngine(this); .... } };
-
@Kai-Nickel said in QJSValue engine() deprecated in Qt5.15:
qjsEngine
Thanks, Kai.
I didn't know the qjsEngine function.
I am in the same use case as you, so that should do the trick.