QML_FILES ...
    [NAMESPACE namespace]
    [IMPORT_PATHS ...]

If versionless commands are disabled, use qt6_target_compile_qml_to_cpp() instead. It supports the same set of arguments as this command.


By default, qmltc creates lower-case .h and .cpp files for a given .qml file. For example, Foo.qml ends up being compiled into foo.h and foo.cpp.

The created C++ files are placed into a dedicated .qmltc/<target>/ sub-directory of the BINARY_DIR of the target passed as an argument to this command. These files are then automatically added to the target sources and compiled as Qt C++ code along with other source files.

Note: This command is in technology preview and may change in future releases.


The target specifies the name of the binary that the QML files belong to. In order for the compilation to succeed, the target is expected to be a valid QML module, defined with qt_add_qml_module() command.

QML_FILES lists the .qml files that are going to be compiled into C++. In most cases, all the target's QML files would be specified in the QML_FILES. This way, QML_FILES argument of this command is equivalent to QML_FILES argument of the qt_add_qml_module() command.

NAMESPACE argument defines a namespace, in which the generated C++ code resides. By default, no namespace is specified for user projects. The code generated from Qt's own sources is put under a QT_NAMESPACE namespace.

IMPORT_PATHS can be used to add locations that contain QML modules. The specified entries are passed to qmltc and allow to correctly import modules that do not reside under the location specified by QLibraryInfo::QmlImportsPath.

While processing QML_FILES, the following source file properties are respected:

  • QT_QMLTC_FILE_BASENAME: use this source file property to specify a non-default .h and .cpp file name, which might be useful to e.g. resolve conflicting file names (imagine you have main.qml that is being compiled, but main.h already exists, so #include "main.h" might not do what you expect it to do). QT_QMLTC_FILE_BASENAME is expected to be a file name (without extension), so any preceding directory is ignored. Unlike in the case of default behavior, the QT_QMLTC_FILE_BASENAME is not lower-cased.

© 2022 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.