JavaScript with Qt Widget application
-
wrote on 20 Jul 2015, 10:00 last edited by MTCA
Is it possible to call javascript function on the event change of ui objects directly, without the help of qml? Most of the tutorials available on internet are based on qml and my aim is to integrate the .ui file directly with .js file.
-
Hi,
No you can't, Qt Widgets are C++ based, you need an interpreter to execute JavaScript code
-
wrote on 21 Jul 2015, 04:05 last edited by
Ohh.. Ok. Thank you so much for your quick reply.
-
wrote on 21 Jul 2015, 11:23 last edited by
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
-
wrote on 21 Jul 2015, 12:14 last edited by
Great!! Things are getting much clear now. Thank you.
-
Hi,
See QJSEngine. It is inside the Qt QML module, but it is a pure JavaScript engine that doesn't process QML. (It can't import .js files, however -- you need to call
evaluate()
dirrectly) -
wrote on 23 Jul 2015, 05:02 last edited by
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?
-
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.
-
wrote on 23 Jul 2015, 07:08 last edited by
Ohh. Sounds great!! Thank you for adding some new things in my knowledge base. :)
10/10