QML script compiler
QML script compiler is available in two versions. One is qmlcachegen, which is a part of the Qt Quick Compiler. Another one is qmlsc, which is a part of the commercial-only add-on Qt Quick Compiler Extensions.
qmlcachegen uses the meta-object system and generates lookups and stores them in a central place, a compilation unit. The compilation unit contains a representation of document structure, compact byte code representation for each function and expression, and native code for functions and bindings that compiler fully understands. The byte code in a compilation unit can be used by the QML engine to avoid re-compilation and to speed up execution.
qmlsc, on the flip side, extends the base functionality of qmlcachegen by providing two extra modes.
To enable static mode in qmlsc, you should pass
QT_QMLCACHEGEN_ARGUMENTS to qt_add_qml_module.
qt_add_qml_module(someTarget ... ) set_target_properties(someTarget PROPERTIES QT_QMLCACHEGEN_ARGUMENTS "--static" )
Warning: qmlsc static-mode generates invalid code if any properties are shadowed in the QML document.
In direct mode, qmlsc assumes that all C++ types used in your QML code are available and can be included as C++ headers to the generated code. Then the generated code accesses or modifies properties by directly calling getters, setters and invokable functions in those headers which makes the execution even faster. This means you have to link to private Qt APIs in CMake.
Warning: Private Qt APIs change often. You will need to recompile Qt for each new version.
Warning: If a type is only defined in a plugin or has no header, you can’t use it in direct mode.
To enable direct mode, you should consider the followings:
- you should pass
qt_add_qml_module(someTarget ... ) set_target_properties(someTarget PROPERTIES QT_QMLCACHEGEN_ARGUMENTS "--direct-calls" )
- Link all the relavant private Qt modules instead of their public counterparts.
qt_add_qml_module(someTarget ... ) target_link_libraries(someTarget PRIVATE Qt::QmlPrivate Qt::QuickPrivate ... )
- Do not set the
PLUGIN_TARGETto be the same as the backing library target.
# direct mode will not function in this setup. qt_add_qml_module(someTarget PLUGIN_TARGET someTarget ... )
© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.