Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Resource System
QtWS25 Last Chance

Qt Resource System

Scheduled Pinned Locked Moved Solved General and Desktop
rccqrccppqmakebuild
9 Posts 3 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • onurAO Offline
    onurAO Offline
    onurA
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • onurAO Offline
          onurAO Offline
          onurA
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Time difference is so big because the compiler has to compile a huge cpp file.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • onurAO Offline
              onurAO Offline
              onurA
              wrote on last edited by
              #6

              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?

              kshegunovK 1 Reply Last reply
              0
              • onurAO onurA

                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?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #7

                @onurA

                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.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                1
                • jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  onurAO 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    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.

                    onurAO Offline
                    onurAO Offline
                    onurA
                    wrote on last edited by
                    #9

                    @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?

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved