JavaScript with Qt Widget application
-
Hi,
No you can't, Qt Widgets are C++ based, you need an interpreter to execute JavaScript code
-
While browsing, I came across this example http://doc.qt.io/qt-4.8/qt-script-calculator-example.html in which the javascript function is called directly on arrival of event from ui form.
-
It's not called directly, it uses the now deprecated QtScript module that is replaced by the QtQML module
-
It seems that using QJSEngine, we can directly evaluate the js function. Then how it is different from QScriptEngine? And why it has been deprecated?
@MTCA said:
how it is different from QScriptEngine? And why it has been deprecated?
Internally, Qt Script uses the JavaScriptCore engine. It is old, its performance is not very good, and it is not 100% compliant with the ECMA standard.
Qt engineers tried to make Qt Script switch from JavaScriptCore to Google's V8 engine. Unfortunately, this task was not feasible (see https://wiki.qt.io/Qt_Script_V8_Port ).
Now, it is expensive for Qt engineers to keep maintaining Qt Script. If they spend time on Qt Script, that means they have less time to fix bugs and add features to other modules. So, they want to deprecate Qt Script and use the new QJSEngine. QJSEngine has better integration with C++ (and QML), and is more compliant with ECMA standards.