Qt Resource System
-
Qt generates a .cpp file when compiling the resource, e.g. images, which are defined in the .qrc file. The compile output is as follows:
/usr/local/Qt-5.5.1/bin/rcc -name images ../myApplication/images.qrc -o qrc_images.cpp
g++ -c -pipe -g -std=c++0x -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_QUICK_LIB -DQT_MULTIMEDIA_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_SQL_LIB -DQT_CORE_LIB -I../myApplication -I. -I../shared_base/Debug -I../shared_base -I/usr/local/Qt-5.5.1/include -I/usr/local/Qt-5.5.1/include/QtQuick -I/usr/local/Qt-5.5.1/include/QtMultimedia -I/usr/local/Qt-5.5.1/include/QtGui -I/usr/local/Qt-5.5.1/include/QtQml -I/usr/local/Qt-5.5.1/include/QtNetwork -I/usr/local/Qt-5.5.1/include/QtSql -I/usr/local/Qt-5.5.1/include/QtCore -I. -I/usr/local/Qt-5.5.1/mkspecs/linux-g++ -o qrc_images.o qrc_images.cppSo as seen in the output, to compile the image resources, two different commands are executed, the rcc and the g++. However, one can simply compile the images with the rcc and register this binary file in the application during run time. I can't understand what this g++ command does and why generating the .cpp is necessary.
Also why does qt include libs such as Multimedia, Gui, etc. into this file and make it larger than just the images?
Note: The images folder is sized 27MB. The generated images.cpp file is sized 66MB and if I compile the images with the rcc-utility myself it is also 27MB and it works just like the 66MB did.
-
Did you read http://doc.qt.io/qt-5/resources.html ? Especially "Compiled-In Resources" section.
You can have your resources as part of your executable (that what you are currently doing). That's why a cpp file is generated. As it is a cpp file it must be compiled like any other cpp file using C++ compiler (in your case g++). The size of the cpp file does not say much about the size of the generated executable. You should compare your executable size and the size of executable without resources + resource file. -
"Also why does qt include libs such as Multimedia, Gui, etc. into this file and make it larger than just the images?" - it does not include that libraries. These are dynamically linked libraries and are not build into your application.
-
When I choose the "Compiled-In Resources" way, the compilation time is about 5 minutes. When I change the .qrc files, I have to wait for 5 minutes but the advantage is the resource are built in the executable.
On the other hand, if I choose to compile the resources myself with the rcc command, it takes less than 2 seconds and then I have to register resources manually.
So I understood now the reason of .cpp generation, but I am not convinced why the time difference is so great.
-
Time difference is so big because the compiler has to compile a huge cpp file.
-
And the configurations is in its optimal form per default? One should not change the configurations for the resource compilation step?
Moreover, what's the best practice when deploying an application (release version)? Building the resources into the executable or provide the compiled binary .rcc and then dynamically load the resources during execution time?
-
Moreover, what's the best practice when deploying an application (release version)? Building the resources into the executable or provide the compiled binary .rcc and then dynamically load the resources during execution time?
It's a design choice and you can do it however it suits you. A rule of thumb would be to put small resources like some little icons for menus and and buttons into the compiled binary, while if you want to use bigger resources as sprites, textures and such, to load them from a separate file.
Kind regards.
-
What do you mean by "configurations"?
Which solution is better depends on your needs. If you integrate your resources into the executable then it will be bigger - even if at runtime you only use some of the resources everything will be loaded into RAM. And if you change some resources you will need to provide a new executable to your users.
So, using external resources is more flexible and will potentially consume less memory. -
@jsulm I meant to change some configurations, if there are some, and fasten the compilation.
So if I choose the external resources step, is it feasible to do the following steps:
-
Can I integrate the rcc command that I have to execute manually in terminal, somehow to the make step of the application, so that it is executed automatically?
-
If I achieve the upper step, can I detect, whether the qrc was changed a new rcc compilation is necessary?
-