[Interest] qt_add_qml_module() RESOURCES vs qt_add_resources()

ekke ekke at ekkes-corner.org
Tue Feb 13 22:52:32 CET 2024


Hi Ulf,

thanks for your hints.

Am 13.02.24 um 21:50 schrieb Ulf Hermann via Interest:
>> 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.

learned about NO_RESOURCE_TARGET_PATH from qmake2cmake tool ;-)

and from documentation of qt_add_qml_module:

...

/For the special case where the backing target is an executable, it may 
be desirable to place the module's |.qml| files and other resources 
directly under the |RESOURCE_PREFIX| instead. This can be achieved by 
specifying the |NO_RESOURCE_TARGET_PATH| option, which may only be used 
if the backing target is an executable./

...

this qml module's target is the executable and the module never will be 
reused

>
> 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.

not really sure what I'll have to do - will read again tomorrow and 
trying to understand ;-)

BTW: this is the (qml) structure of my apps:

qml/Main.qml
     pages/MyPage.qml
          /xxx.qml
     popups/MyPopup.qml
     ...

>
> best regards,
> Ulf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240213/79abd337/attachment.htm>


More information about the Interest mailing list