Hello,
I’d like to use the Qt Resource System (qrc) for distributing my app. I developed it without qrc and used relative paths to the resources, which was no problem. But I don’t want the qml source code to be visible when distributing the app, so I switched everything to qrc. This also works fine with all images that are displayed in the “normal” way, like this:
Image {
source: "../images/test.png"
}
But I have some images which are dynamically loaded (it’s a game, so some game objects are created dynamically), and these are not displayed anymore. My code looks like this:
property url imagePath: "../images/test.png"
property url imagePath2: "../images/test2.png"
function getImagePath() {
switch (someInteger) {
case 0: return imagePath;
case 1: return imagePath2;
}
}
Image {
source: getImagePath()
}
Which one of these image will be used is decided at runtime. When I switched to qrc, these images were not visible anymore and I don’t know why.
Strangely, it works when I open the release build in the IDE (I use Visual Studio) , but it doesn’t work when I open the executable. I also removed the image folder from the visual studio project, to see if the app still uses the relative paths when creating the dynamic objects, but it doesn’t. The behaviour is the same: It works in the IDE, but not outside. Is there any special file that I have to include in the release package so that it works?
I also tried different versions of the url in the qml files, for example
“qrc:/images/…”
“qrc:///images/…”
“: / images/…”
But none of these work, and I don’t think that’s the problem because in the Qt documentation, I always read that you only have to use the qrc prefix in the C++ files. In the qml files, everything should work as before…
Do you have any suggestions? Thanks!
↧








