OnurA
OnurA

Reputation: 651

Why does Qt generate a .cpp file out of .qrc?

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.cpp

So 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 it 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.

Upvotes: 4

Views: 2223

Answers (2)

sulin
sulin

Reputation: 398

The cpp file generated by rcc is bigger, because every byte in images will become 0x00 code in cpp.

If your file is 100KB, the cpp file may be 500KB, it's ok.

The final executable file will not so big, binary is binary, cpp is cpp.

Upvotes: 1

Andrejs Cainikovs
Andrejs Cainikovs

Reputation: 28474

...one can simply compile the "images" with the rcc and register this binary file in the application during run time.

As @vahancho pointed out, Qt resources can be loaded dynamically too if you generate a binary resource data with -binary option of rcc. That file can be loaded with QResource::registerResource() function.

I can't understand what this g++ command does and why it is necessary.

It builds the object file, which is then linked into the binary at a later stage.

Also why does qt include libs such as Multimedia, Gui etc into this file and make it larger than just the images?

Including the libs doesn't necessary mean the binary will be larger. Linker will produce a binary only with those objects that are used in your code.

Upvotes: 2

Related Questions