Loading resources in a file embedded in a resource file
-
My problem sounded like this : http://qt-project.org/forums/viewthread/10477 but, bad luck, it's not.
My problem starts the same way : I put my qml files into resource file (qmlfiles.qrc) and I want to access images into these qml files. But the fact is that my images are in another resource file (image.qrc)
So for example I'm trying to do this :
@Item{
source: "qrc:/sprites/myImage.png"
}@and the qrc looks like this :
@<RCC>
<qresource prefix="/sprites">
<file alias="myImage">images/myImage.png</file>
</qresource>
</RCC>@But in the log, there is QML Image: Cannot open: qrc:/sprites/myImage.png. Is it because he's trying to access a file in a resource file that is not the same where the qml file is ? Any idea for that problem ?
-
Having 2 separate resource files should not be a problem, the system is completely transparent and can work with multiple QRC files (even sharing the same prefix!).
-
Yeah that's why it sounds weird to me. I never had such problem with qrc files on my other Qt (but without qml) applications.
The way of loading a qrc item is "qrc:/prefix/myFile", right ? If I don't make a mistake, then I don't see how that cannot work...
-
Yes, it's either ":/prefix/file" or "qrc:/prefix/file" (both should work the same, but rarely do). You can try passing the path without any reference to QRC, though. Since you are loading QML from the resource file, the engine already assumes all the paths are QRC-based, too. So you can try with simply:
@
Image {
source: "sprites/myImage.png"
}
@ -
I've solved the problem by putting some alias and regrouping the qml and image files into the same .qrc file but organized with different prefixes.
But now I've got another problem. I've put all my qml files into the same qrc file and I'm trying to initiate a pathview with a ListModel. The List Model is in a file alone and the PathView in another qml file.
I'm trying to do :
@PathView {
id: myPathView
delegate: myDelegate
model: myModel
[...]
}@with my ListModel looking like this :
@import QtQuick 2.0
ListModel {
id: myModel
ListElement {
name: "MyElement1"
}
ListElement {
name: "MyElement2"
}
ListElement {
name: "MyElement3"
}
}@But the pathview doesn't find the ListModel. When I tried something similar with a test projet and qml files that weren't in a .qrc file, it worked without any problem. It seems that when .qrc are involved, scopes are different... Any ideas ?