Is it possible to get the absolute file path of the resource file? [SOLVED]
I have a resource file which contains a few images. I'm using an external library which asks for path to the file in its constructor. I need to give it to the constructor, but I don't know how can I extract the path from resource file, not the
/home/john/Pictures/bubble.jpg. I tried to use the next variant:
QFileInfo image(":/images/bubble.jpg"); QString imagePath = image.absoluteFilePath();
But it returns the
resource filepath -
Maybe it's possible to create folder within the project and use something like:
QString imagePath = "$PROJECT_DIR" + "/images/bubble.png"
But I couldn't find the appropriate variable. I tried to use
getenv()as well as
qgetenv- got nothing. I know there's a
$$_PRO_FILE_PWD_which returns the folder with
.profile, but I didn't figure out how to use
What can be the solution to this problem? Not necessarily that it would be a completely different one, it's ok. I just need to be able to have a folder within the project where I can store images and get the absolute path of each file.
Qt resource "is mechanism for storing binary files in the application's executable". So you don't have the file in your file system after you deploy your application. Only in development they exists.
@TioRoy So, is there anything I can do in my situation?
hmm, the resource file is compiled into the application.
So are you sure an external library can load it from the exe ressources ?
can tell where you exe is run from and you can construct a full path to image folder using that.
Please notice that you will need a copy of the image folder to the build directory as that is where your exe is being run from until deployment.
This post is deleted!
@mrjj Yeah, it works! Also, in the
releaseversion it will seek for the image not in the
builddir, but in the primary folder of the project, am I right?
well if run from inside the IDE / creator, and it is set to release mode, it will run from the release folder. as far as i know. just like the debug folder.
If you copy the exe file to another folder and run it there , then it will be that folder.