Details
-
Task
-
Resolution: Duplicate
-
P2: Important
-
5.14, 5.15
Description
There is detailed documentation about how to create shared QML plugins and it works fine, but there is no documentation about how to create them statically. And the plugins can't be loaded successfully if they are compiled statically.
I've seen there are a few paragraphs teaching people how to create static plugins, but it's not about QML plugins. And why static QML plugins can't be loaded has nothing to do with Q_INIT_RESOURCE() or anything like that, the main problem is the plugin can't be registered and recognized by the QML engine.
Actually there's more work to do if people want to build a static plugin, because I opened "qml_plugin.prf" and "qml_module.prf" and found something not mentioned anywhere in the documentation.
I hope this issue can be fixed soon because it's a common use case and it's really a headache without any documentation to follow.
I now figured out how to build QML plugins statically after digging into some .prf files and QML plugins:
For the .pro file, we have to add one line:
QMAKE_MOC_OPTIONS += -Muri=$$QML_IMPORT_NAME
And all .qml files and the qmldir file (and all other assets if exist) have to be packed into the static library, under the "/qt-project.org/imports/balabalabala" prefix.
For the source file, we have to add the following line:
extern void qml_register_types_balabalabala();
And we should use it in the constructor function:
volatile auto registration = &qml_register_types_balabalabala; Q_UNUSED(registration)
Then the plugin can now be built as a static library and it can be recognized and loaded by the QML engine successfully.
These steps are not complicated and are easy to understand, but I really like it be documented officially.
Attachments
Issue Links
- is replaced by
-
QTBUG-95148 Document use case of linking multiple static qml modules into an application
- Closed
- is required for
-
QTBUG-93257 qt6_import_qml_plugins does not compose
- Closed
- relates to
-
QTBUG-88763 Review / refactor public CMake API that is marked as Technical Preview
- Closed
-
QTBUG-89274 Make public, documented API for compile time QML type registration with CMake
- Closed
-
QTBUG-91621 Add a CMake wrapper for building a QML-friendly library
- Closed
For Gerrit Dashboard: QTBUG-82598 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
346273,36 | Refactor and update qml CMake API | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
354443,9 | Add initial qml CMake API docs | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
361522,2 | Add initial qml CMake API docs | 6.2 | qt/qtdeclarative | Status: MERGED | +2 | 0 |