Using QML Modules with Plugins
QML modules may use C++ plugins to expose components defined in C++ to Qt Quick applications.
To create a QML module and make it appear in the Components view:
- Create custom components and place all the
.qml
files in a directory dedicated to your module. For example,imports\asset_imports
. - Specify the path to the directory that has the module in the .qmlproject file of the application where you want to use the module as a value of the
importPaths
variable. For example,importPaths: [ "imports", "asset_imports" ]
. - Create a
qmldir
file for your module and place it in the module directory. For more information, see Module Definition qmldir Files. - Create a directory named
designer
in your module directory. - Create a
.metainfo
file for your module and place it in thedesigner
directory. Meta information is needed to display the components in Components. Use a metainfo file delivered with Qt, such asqtquickcontrols2.metainfo
, as an example. - Build your module using the same Qt version and compiler as Qt Design Studio.
Your module and components should now appear in Components.
Note: If Qt Design Studio cannot find the new QML module, build the project and then go to Tools > QML/JS > Reset Code Model to reset the code model. For more information about how to show the Tools menu, see Customizing the Menu Bar.
Running QML Modules in Design Mode
A QML emulation layer (also called QML Puppet) is used in the Design mode to render and preview images and to collect data. To be able to render custom components correctly from QML modules, the emulation layer must be built with the same Qt version and compiler as the QML modules.
Qt Design Studio runs projects using a specific version of Qt. In Qt Design Studio, find the Qt runtime version in the bottom toolbar.
A plugin should behave differently depending on whether it is run by the emulation layer or an application. For example, animations should not be run in the Design mode. You can use the value of the QML_PUPPET_MODE
environment variable to check whether the plugin is currently being run by an application or edited in the Design mode.
See also Resetting the Code Model.
Available under certain Qt licenses.
Find out more.