External protected resources
-
hello dear programmers .
as the title said i need to use a external resources file for my project.
the case is that i have a gallery ,designed and ready but i used Qresource files (.qrc)
to handle my image + videos.
the problem is that qrc files in the final compile turn into 1 solid ".exe" which has a
huge size and it will get bigger because i need to update it's content later on.
so any suggestion guys? -
-
ThnQ sir ,i compiled my qrc files into one rcc file.
but i didn't understood the registerResource part.
i changed theRESOURCES += \ images.qrc
to
RESOURCES += \ images.rcc
and compiled my code again ,now all the images and videos are not loaded.
i think i should change the typical addresses that i used in my application but don't know how.
example :QPixmap image(":/new/prefix1/imgs/1_02.jpg")
-
@md2012
as written on the doc page you need to useQResource::registerResource("/path/to/myresource.rcc");
instead of setting it via the RESOURCES qmake variable. Since you do not want it to be compiled into the binary. -
well i removed
RESOURCES += \ images.rcc
from the .pro so the resources won't compile into binary .that worked well ,my .exe size decreased about 10 times.
now i have to use QResource in my code to address the files in the code.QResource b; b.registerResource("/images.rcc");
now there is one .qrc file in the images.rcc.
how should i address the code below for example?QMovie *movie = new QMovie(":/new/prefix1/imgs/1.gif");
-
@md2012
exactly like you did before.
If the files are still not loaded there is something wrong with your path. Check the bool return value of registerResource().On what platform are you on? Note that the path (
/images.rcc
) you've posted means different things on unix and windows for example.btw. you do not need to create a QResource instance. registerResource() is a static method.
So use it as i've written (QResource::registerResource()
) is enough. -
@raven-worx
i use windows .
well now i have the code below in my main.cppQResource::registerResource("/images.rcc");
also i checked the bool return value and you were right output is false.
qDebug()<<QResource::registerResource("/images.rcc");
but i checked every where i could for the images.rcc include :
release folder
debug folder
build folder
main folder which the original cpp and header files are stored. -
@md2012
you called the rcc command in some folder, probably it's there (when you didn't change the-o
parameter to contain a path). -
@raven-worx
i know where is the rcc file ,i changed the location of images.rcc to the
release folder
debug folder
build folder
main folder which the original cpp and header files are stored.
There must be something wrong with accessing the file because im pretty sure the
path "/file.format" will lead to the build folder. -
@md2012
It depends where the current working directory is set at the time of calling.
You can check withQDir::currentPath()
-
ThnX Again @raven-worx
it was pointing to entirely diffresnt drive
"C:/Users/MeHrAnM.D"
my project path is
D:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-tarh_bartar-Desktop_Qt_5_7_1_MinGW_32bit-Release
pretty much confusing ,huh?
i started the project on Qt 5.2 ,ended up on Qt 5.7 for the android compiler and newer version.
QDir::currentPath() showed me that the current working directory was not there.
changed the directory of project to there and problem solved. -
Just as a note.
There is also
Debug() << "App path : " << qApp->applicationDirPath();Which is where exe is. So I use that for loading files "next" to the exe no matter where is is.
debug/release or deployment folder.