Qt 6.12 LTS is out! See what's new in the release
blog
How to put a QML component into a QML module? (CMake)
-
How can I take a QML component (.qml file) and put it in a separate QML module, in CMake?
At the moment I'm including all QML components in the main app module and that works fine. But when I try to move some of them into separate modules (and add the import statement in main.qml of course), I get the runtime error "MyImportedComponent is not a type".
NB: In Qt Creator, in main.qml, the import statement is parsed fine and MyImportedComponent shows up correctly colour-coded (not M300 error).
Here's what I tried...
All in the app module works fine:
qt_add_qml_module(appMyProject URI MyProject VERSION 1.0 QML_FILES main.qml MyImportedComponent.qml ) target_link_libraries(appMyProject PRIVATE Qt6::Quick)Separate module doesn't:
qt_add_qml_module(SeparateModule URI SeparateModule VERSION 1.0 OUTPUT_DIRECTORY SeparateModule QML_FILES MyImportedComponent.qml ) qt_add_qml_module(appMyProject URI MyProject VERSION 1.0 QML_FILES main.qml ) target_link_libraries(appMyProject PRIVATE Qt6::Quick SeparateModule)