[Interest] Qt scripting with JavaScript

Richard Weickelt richard at weickelt.de
Thu Jun 18 16:39:45 CEST 2020

> Is the QJSEngine a complete replacement of QScriptEngine ?

No, not complete. QJSEngine provides less APIs and less control of the script execution and context arrangement. Whether your application is portable depends on which features of QtScriptEngine you use.

Do you:
- swap out the global object,
- push/pop contexts,
- use QScriptClass
- throw script exceptions in constructors of script classes defined in C++
- use variable argument lengths in method calls from JS to C++?

then porting will not be straight forward. Otherwise it should be. Either evaluate your scripts directly with QJSEngine::evaluate() or use QQmlExpression if you need context hierarchies.

> Can I use the Qt QML module-contained QJSEngine for a classical
> QWidgets-based
> program ? If so, is the JS programming in this setting very different than
> what
> I am used to with Qt Script ?

Yes, you can use the QML/JS engine in any context, even without a GUI. QtQuick is just a bunch of components written in QML that you don't need to use at all.

More information about the Interest mailing list