QmlModule
QML extension module consisting of a plugin library and QML files. More...
| Since: | Qbs 3.4 |
| Inherits: |
- List of all members, including inherited members
- QmlModule is part of List of All Items.
Properties
- modulesInstallDir : string
- uri : string
Detailed Description
A QmlModule is a convenience item that mirrors the functionality of CMake's qt_add_qml_module() command. It combines a plugin library with automatic QML type registration, qmldir generation, and resource embedding, so that the module can be imported from QML using the module-based import syntax (rather than file or directory imports).
Note: This functionality requires Qt 6.2 or later.
What QmlModule Does Automatically
- Runs
qmltyperegistraron C++ files decorated withQML_ELEMENTor similar macros and produces aplugins.qmltypesfile. - Generates a
qmldirfile listing all QML files and, if Qt.qml.loadedAtRuntime istrue, apluginline for dynamic loading. - Embeds all QML files, JavaScript files, and the
qmldirinto the plugin's resources at:/qt/qml/<URI>/, enabling theprefer :/qt/qml/<URI>/directive so the QML engine uses embedded resources rather than files on disk. - Installs
qmldir,plugins.qmltypes, as well as QML and JavaScript files to modulesInstallDir. When the plugin is loaded at runtime (Qt.qml.loadedAtRuntime istrue), the library binary is installed there too.
Usage
Dynamic Plugin — Linked Directly by the Application
The application lists the module as a dependency, which links the plugin at build time. The QML engine finds module types through the pre-registered module without loading a plugin file at runtime. Because Qt.qml.loadedAtRuntime defaults to true for dynamic libraries, set it to false to suppress the plugin line in the generated qmldir.
// mymodule/mymodule.qbs QmlModule { name: "mymoduleplugin" uri: "com.example.MyModule" Qt.qml.loadedAtRuntime: false files: ["MyItem.qml", "mytype.h", "mytype.cpp"] } // app/app.qbs CppApplication { Depends { name: "mymoduleplugin" } // ... }
Dynamic Plugin — Loaded at Runtime via Import Path
In this mode the plugin .so is not linked by the application. Instead, the QML engine discovers and loads it at runtime through the QML import path. Qt.qml.loadedAtRuntime defaults to true for dynamic libraries, so no override is needed:
QmlModule {
name: "mymoduleplugin"
uri: "com.example.MyModule"
files: [...]
}However, you need to point the QML engine to the install location via QML_IMPORT_PATH or QQmlEngine::addImportPath().
Static Plugin
For platforms that require static linking (iOS, tvOS, watchOS), the type is automatically set to staticlibrary. On other platforms, override type directly. Qt.qml.loadedAtRuntime defaults to false for static libraries, so no override is needed there either.
QmlModule {
name: "mymoduleplugin"
uri: "com.example.MyModule"
type: ["staticlibrary"]
files: [...]
}
CppApplication {
Depends { name: "mymoduleplugin" }
// ...
}Property Documentation
modulesInstallDir : string |
The directory where qmldir, plugins.qmltypes, and QML files are installed. When Qt.qml.loadedAtRuntime is true, the plugin library is also installed here so the QML engine can find it.
Default: Qt.qml.qmlPath + "/" + uri.replace(/\./g, "/")
uri : string |
The QML module URI, for example "com.example.MyModule". This value is required.
The URI is used as the Qt.qml.importName for type registration, written as the module line in the generated qmldir, and determines the resource path :/qt/qml/<URI>/ where QML files and the qmldir are embedded.
Default: Undefined
© 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.