Is it possible to get the absolute file path of the resource file? [SOLVED]
-
wrote on 9 Jul 2015, 18:00 last edited by sosun 7 Sept 2015, 20:20
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
:/images/bubble.jpg
, but/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 file
path -:/images/blah-blah
.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 asqgetenv
- got nothing. I know there's aqmake
variable called$$_PRO_FILE_PWD_
which returns the folder with.pro
file, but I didn't figure out how to useqmake
variable.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.
-
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
:/images/bubble.jpg
, but/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 file
path -:/images/blah-blah
.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 asqgetenv
- got nothing. I know there's aqmake
variable called$$_PRO_FILE_PWD_
which returns the folder with.pro
file, but I didn't figure out how to useqmake
variable.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.
wrote on 9 Jul 2015, 18:18 last edited byQt 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.
-
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.
-
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
:/images/bubble.jpg
, but/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 file
path -:/images/blah-blah
.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 asqgetenv
- got nothing. I know there's aqmake
variable called$$_PRO_FILE_PWD_
which returns the folder with.pro
file, but I didn't figure out how to useqmake
variable.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.
@sosun
hmm, the resource file is compiled into the application.
So are you sure an external library can load it from the exe ressources ?QCoreApplication::applicationDirPath()
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.also see
http://stackoverflow.com/questions/23844136/getting-paths-of-qrc-files-in-qt -
wrote on 9 Jul 2015, 18:31 last edited byThis post is deleted!
-
@sosun
hmm, the resource file is compiled into the application.
So are you sure an external library can load it from the exe ressources ?QCoreApplication::applicationDirPath()
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.also see
http://stackoverflow.com/questions/23844136/getting-paths-of-qrc-files-in-qt -
@mrjj Yeah, it works! Also, in the
release
version it will seek for the image not in thebuild
dir, but in the primary folder of the project, am I right?@sosun
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.
1/7