[Development] QML 3 and JavaScript

Dmitriy Purgin dpurgin at gmail.com
Mon Nov 11 09:10:48 CET 2019

Hi all,

as we learned at the recent Qt World Summit in Berlin, we're getting QML 3
with Qt 6. There are some cool features and changes to improve the clarity
and the performance of the QML part but there is one thing that bothers me:
the optionality of JavaScript.

What I didn't quite get is whether JavaScript becomes optional in QML 2
already and will be disabled in QML 3, or will it be optional in QML 3
only, and QML 2 remains as it is now?

As for QML 2, there is a lot of JavaScript code in the existing codebase.
Just look at Sailfish OS (actively developed) or Ubuntu Phone, there are
tons of logic implemented in QML/JavaScript. I understand that UI should be
separated from the logic but in the real world, you can't completely
enforce this that unless it is technically impossible. And I'm afraid if it
becomes impossible with QML 3, this will be considered a step back by many
Qt users.

Our company has multiple customer projects where JavaScript is actively
used to implement parts of the view logic. One of the projects is a
domain-specific framework where we do the framework part in C++, and the
customer implements almost all of the logic themselves solely in QML.

I'm sure some parts of the codebase can be rewritten to be declarative-only
and work exclusively through bindings but there is another thing: there are
QML components that *require* imperative code to work with them: the QML
WebSocket type [1], sometimes even Animation [2] or Timer [3]. And there
are also signal handlers that can execute arbitrary JavaScript code now,
and even a simple console.log() is so practical for debugging.

(btw how do you guys debug complex bindings and state changes? I know the
QML debugger exists but in most cases it's quicker to add a console.log()
to the property change and see what's wrong).

I understand that QML 2 is not going anywhere in Qt 6 but maintaining both
QML 2 and QML 3 will be a burden for the developers of the Qt Framework,
and I'm afraid QML 2 won't get much love after QML 3 is released. Just as
it happened to Widgets, it will be in the "done" state.

Another question is: how will we control the JavaScript engine? Will there
be a compile switch to disable or enable it (like QtQuick Compiler) or will
it be a runtime option to the QML engine? If it's a runtime option, there
will still be the library size penalty for the JavaScript engine that we,
in fact, don't need, right?

[1] https://doc.qt.io/qt-5/qml-qtwebsockets-websocket.html
[2] https://doc.qt.io/qt-5/qml-qtquick-animation.html
[3] https://doc.qt.io/qt-5/qml-qtqml-timer.html

Thanks & cheers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20191111/8cf627a8/attachment.html>

More information about the Development mailing list