[Interest] qt_add_qml_module() RESOURCES vs qt_add_resources()

ekke ekke at ekkes-corner.org
Tue Feb 13 18:33:41 CET 2024


Am 13.02.24 um 16:38 schrieb Sze Howe Koh:
> On Tue, 13 Feb 2024 at 22:10, ekke <ekke at ekkes-corner.org> wrote:
>> ...
> Hi Ekke,
>
> There is no bug. If your resource files are part of your QML module,
> then they will be in the same folder as your *.qml files. Probably
> "qrc:/Main_Module/images/..." in your case.
>
> To list your app's resource file paths, add the following lines to
> your main() function:
>
>      QDirIterator qrc(":", QDirIterator::Subdirectories);
>      while(qrc.hasNext())
>          qDebug() << qrc.next();
>
>
> Regards,
> Sze-Howe

Hi Sze,

you're right.

Also Nils, you were right.

Because it was working after adding images.qrc to qt_add_executable() I 
thought all is OK with pathes.

After getting app's resource file pathes I've seen that images were 
twice there:

as ":/images" and also as ":/qt/qml/Main_Module/images"

Also I thought as long as I'm not setting QTP0001 to NEW, the old 
behavior is used.

Setting QTP0001 to OLD I got warning that this probably won't work in 
future releases.

So let this to NEW.

Setting "RESOURCE_PREFIX /" makes it something better, but  
"Main_Module" was still there as prefix.

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

now getting ":/images" ...

l loaded the Module this way:

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

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

but this one works:

engine.load(QUrl(QStringLiteral("qrc:/qml/Main.qml")));

Thx Sze - listing the resource file pathes was the key to success :)

Now I understand how it works and can use my existing file structure and 
go on:)

ciao

ekke



More information about the Interest mailing list