[Interest] qt_add_qml_module() RESOURCES vs qt_add_resources()

Ulf Hermann ulf.hermann at qt.io
Tue Feb 13 21:50:06 CET 2024


> Setting NO_RESOURCE_TARGET_PATH removed the prefix and fixes the pathes 
> for me.

[...]

> engine.loadFromModule("Main_Module", "Main");

Indeed, if you make the module invisible, you cannot load from it. 
NO_RESOURCE_TARGET_PATH is one of the "NO" options. They are called "NO" 
for a reason: You shouldn't use them.

> doesn't work, also "qml/Main" doesn't work

That's wrong on two levels already. You should not put your QML files 
into a subdirectory inside your QML modules. This makes the implicit 
import of you QML files different from the module they belong to. As a 
result, singletons will misbehave, among other things. Usually you could 
fix that by explicitly importing your module from each of your QML 
files, but alas, your module is invisible because of 
NO_RESOURCE_TARGET_PATH. So you cannot import it.

I've hidden the foot gun, but you've found it.

Instead of putting files in the "qml" subdirectory into the top level 
QML module, make a separate QML module called "Main_Module.qml" inside 
the subdirectory. You don't have to move your QML files. You only have 
to add another CMakeLists.txt file with another qt_add_qml_module next 
to them. Then, at least their implicit import will be the same as the 
module.

best regards,
Ulf


More information about the Interest mailing list