Qt Quick Compiler
The Qt Quick Compiler is a development add-on for Qt Quick applications which allows you to compile QML source code into the final binary. When you use this add-on, the application's startup time is significantly improved and you no longer need to deploy .qml files together with the application.
Note: Since Qt version 5.11, the functionality of the Qt Quick Compiler has been integrated into the Qt Quick module itself. This separate add-on remains available in the earlier long term support releases of Qt.
Unfortunately this approach has some disadvantages: On application startup, several .qml files need to be parsed and dynamically compiled before the user interface can become visible and interactive. This is rarely a problem during application development itself, however it is an unnecessary step for a finally released application, as the ability for the end user to modify the qml source code like a developer is usually not required. Conceptually, this is similar to how a release build of C++ code cannot be used with a debugger.
As .qml files are loaded at run-time, it is necessary to deploy them together with the released application. For proprietary applications that wish to hide the source code from the end user, this is an unacceptable restriction.
Lastly, some platform versions such as iOS or Windows RT do not permit the dynamic generation of machine code. As a fallback QML provides an interpreter to allow for the full use of QML, but it comes at the expense of a longer execution time.
Compiled Qt Quick is an elegant solution to these problems: .qml files as well as accompanying .js files can be translated into intermediate C++ source code. After compilation with a traditional compiler, the code is linked into the application binary. This entirely eliminates the need of deploying QML source code, it reduces the application startup time and allows for a much faster execution on platforms that do not permit Just-in-time compilation.
The Qt Quick Compiler package consists of the compiler as a command line tool as well as a build system integration.
The integration into the build system happens at the level of the Qt Resource System. In order to use the Qt Quick Compiler, your application needs to be prepared:
- Create a
.qrcfile for your application and include all the files your project needs, including
- Add the file name of your
- Change your application to use
qrc: URLs instead of
file: in order to become file system independent.
- This way all dependent files are bundled into your application binary and you should verify that your application works without the
.qmlsource code in the file system.
When your application has been converted to use the Qt Resource System, you can activate the integration with the Qt Quick Compiler by passing
CONFIG += qtquickcompiler to qmake, for example on the command line or in the build settings of your project in Qt Creator, as additional argument in the
qmake build steps.
After activating the Qt Quick Compiler in the build integration, the build system will automatically execute the tool to compile your
.js files into the binary and avoid the inclusion of their source code in the resource system.
If you have
.js files which should not be compiled but just bundled by the resource system, then you can omit them from the compilation by specifying the resources files that contain them in the
QTQUICK_COMPILER_SKIPPED_RESOURCES variable in your project file, like below:
QTQUICK_COMPILER_SKIPPED_RESOURCES += bundle_only.qrc
If you are building your application with the CMake build tool, then the same principles of using the resource system apply. See the separate Building with CMake article for details about the CMake specific syntax.
© 2018 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.