[Interest] Linking against QML modules

Fabian Kosmale fabian.kosmale at qt.io
Wed Apr 9 10:35:01 CEST 2025


Hi,

(re-adding the mailing list, got dropped in last mail)



> the plugins are all auto-generated. I tried linking just against the 
> backing target, but then QML never finds the modules. Might this be 
> related to Q_IMPORT_QML_PLUGIN?

While the Q_IMPORT_QML_PLUGIN should removed when the plugin is not 
needed, I don't expect it to cause any harm either, notably it shouldn't 
lead to the plugin not being found.

You could double check that when you start the application, a call to
QQmlModuleRegistration::QQmlModuleRegistration with your module's URI 
occurs. That should happen in a static initializer of a global which is 
part of your QML module's backing library.

> I'm using CMake version 3.31.5. We're not using qt_add_executable 
> though, because we have our own flavor of add_executable. Does 
> qt6_import_qml_plugins also work for QML modules, so that one QML module 
> is automatically linking against another one it's using in its QML code?

3.31 should be new enough, and qt_add_executable is actually not needed 
when you call  qt_import_qml_plugins manually. One thing to check: Did 
you call it after all target_link_libraries calls? Otherwise it might 
miss dependencies.

Kind regards,
Fabian


More information about the Interest mailing list