Qt Qml

The Qt Qml module provides a framework for developing applications and libraries with the QML language. It defines and implements the language and engine infrastructure, and provides an API to enable application developers to register custom QML types and modules and integrate QML code with JavaScript and C++. The Qt Qml module provides both a QML API and a C++ API.

Using the Module

QML API

The QML types of the module are available through the QtQml import. To use the types, add the following import statement to your .qml file:

import QtQml

The Qt QML module contains the QML framework and important QML types used in applications. The constructs of QML are described in the The QML Reference.

The QML API of the Qt QML module provides a number of QML Object Types, QML Value Types and namespaces.

C++ API

Using a Qt module's C++ API requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake.

The C++ API contains some important classes you should get familiar with. It also provides types to hold JavaScript values.

Building with CMake

Use the find_package() command to locate the needed module component in the Qt6 package:

find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)

For more details, see the Build with CMake overview.

To provide foreign QML type support for a non-QML library, locate the QmlIntegration module as follows:

find_package(Qt6 REQUIRED COMPONENTS QmlIntegration)
target_link_libraries(mytarget PRIVATE Qt6::QmlIntegration)

See qt6_generate_foreign_qml_types for details.

Building with qmake

To configure the module for building with qmake, add the module as a value of the QT variable in the project's .pro file:

QT += qml

Registering QML Types and QML Modules

In order to register types for usage with QML you first need to define a QML module, preferably using qt_add_qml_module in CMake. Then, you can add C++ headers to your new module, and define types to be exposed to QML in them.

Tweaking the engine

There are a number of knobs you can turn to customize the behavior of the QML engine. The page on configuring the JavaScript engine lists the environment variables you may use to this effect. The description of the QML Disk Cache describes the options related to how your QML components are compiled and loaded.

Articles and Guides

These articles contain information about Qt Qml.

Reference

Licenses and Attributions

Qt QML is available under commercial licenses from The Qt Company. In addition, it is available under free software licenses. Since Qt 5.4, these free software licenses are GNU Lesser General Public License, version 3, or the GNU General Public License, version 2. See Qt Licensing for further details.

Furthermore Qt QML in Qt 6.7.1 may contain third party modules under following permissive licenses:

JavaScriptCore Macro Assembler

BSD 2-clause "Simplified" License

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