[Interest] qt_add_qml_module() RESOURCES vs qt_add_resources()
Ulf Hermann
ulf.hermann at qt.io
Fri Feb 16 21:06:58 CET 2024
Hi Ekke,
> 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
> ...
In QML these are 3 Modules:
* A module called "qml" with an addressable component "Main"
* A module called "qml.pages" with an addressable component "MyPage" and
an internal component defined in xxx.qml
* A module called "qml.popups" with an addressable component "MyPopup"
If you put all the components into the same module, and then add any
custom attributes (singleton or revision) to either MyPage or MyPopup,
you're in for a surprise: The attributes will not be applied if you use
the component from another .qml file in the same directory. For example
if you made MyPage a singleton and then used it from xxx.qml, it would
give you a confusing error message.
This is because MyPage would be imported via the implicit import of
xxx.qml, which knows nothing about the module you've declared one
directory up. The implicit import does not contain the information about
singletons.
This is why it's generally a good idea to make the implicit import the
same as the module a component belongs to.
I have understood, though, that nobody wants to follow this rule. I'll
come up with some technical solution that allows you to declare either a
module spanning multiple directories or a collection of modules, each
with its own directory. with a single CMake function call. The earliest
possible version for that to surface in is 6.8, though.
best regards,
Ulf
More information about the Interest
mailing list