Loading Resource files in Desktop/ios application
-
Here is an exact example from that link.
@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Q_INIT_RESOURCE(graphlib);QFile file("qrc:/graph.png"); ... return app.exec();
}
@So, yes the qrc: is part of the path when using QFile.
-
Ok, I tried the following:
@qrc:/cube.gly
qrc:/packets/cube.gly
qrc:/assets/packets/cube.gly@None of these work. qrc:/assets/packets/cube.gly should have been the correct one. But it fails.
cube.gly is the actual file.
packets is the prefix
assets is the .qrc file.
-
Oh ok, you only need the prefix and not qrc file name. You do need the Q_INIT_RESOURCE if the qrc is in a library.
This should have worked.
@qrc:/packets/cube.gly@
I can't think right now to help point you in the right direction.
-
I'm thinking that this problem is due to the fact that my asset loader is in a library. Does my library .pro file require this?
@RESOURCES +=
assets.qrc@I figured the resources would be available to all the components in my main application
-
Yes, your pro file for your library must have the RESOURCES += so that the qrc file is compiled. All a qrc file is is a xml file. When that file is compiled by the rcc, the output is then used to compile those resources into your binary. To reference those resources, you must use Q_INIT_RESOURCE outside of any namespace.
-
Hi,
Something's not clear here. Are you compiling the resources in your application and then try to access them in your library ?
-
SGaist,
Yes. My library has the file loader in it. When I read from a harddrive, I can specify a path and everything is great.But Qt's resource system seems to choke on the same basic design. It doesn't work like a hard drive at all. And another question I have is this. Does it load everything into memory when the app starts up? Thats ridiculous if does. I will be putting hundreds of megabytes of data in here. The idea is I want to load them into memory as I need it-like I do with a harddrive.
With XCode, I can include assets (ie, image files, data files [such as 3d model assets], etc.) It puts the content in the bundle and I can access it just like I can on my mac--I just need the bundle path. I am having a hard time wrapping my head around how this is done in Qt.
-
If you plan on hundreds of megabytes then you're using the wrong tool. Qt's resources are not meant to bundle that much data. Each resource will be compiled in your application.
However you still can use iOS assets, see "here":http://qt-project.org/doc/qt-5/platform-notes-ios.html
-
Forgot to add to get the path you want you have QStandardPaths
-
After reviewing your information, its clear I'm taking the wrong approach using a resource file. I understand now what the intent of the resource file is. It isn't to load my image/game assets.
On iOS, it looks like I need to look at using QMAKE_BUNDLE_DATA to package up my content. I don't yet know what I am to do on Android. I'm sure I'm going to have a few more questions ;)
-
Indeed, game assets are way to heavy for resources.
AFAIK, you should be able to use QMAKE_BUNDLE_DATA also on android