Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt and standard resource system
QtWS25 Last Chance

Qt and standard resource system

Scheduled Pinned Locked Moved Solved Installation and Deployment
resources
9 Posts 7 Posters 5.5k 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.
  • S Offline
    S Offline
    szaman
    wrote on 21 Jan 2016, 19:24 last edited by
    #1

    This is my first post, so hello everyone.

    I would like to know is it possible to use standard resources with Qt.
    I have build my Qt project with MSVC so I cant use Qt resources (I suppose). Is it possible to extract resources and use with for example QIcon?

    Example:
    resource.h

    #define IDB_ICO_MAIN			110
    #define IDB_ICO_CONFIG			111
    

    resource.rc

    IDB_ICO_MAIN		RCDATA		"imain.png"
    IDB_ICO_CONFIG		RCDATA		"iconfig.png"
    

    window.cpp

    (...)
    QIcon icon_main = new QIcon( [IDB_ICO_MAIN] );
    QIcon icon_config = new QIcon( [IDB_ICO_CONFIG] );
    

    Something like that.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      ValentinMichelet
      wrote on 21 Jan 2016, 19:56 last edited by ValentinMichelet
      #2

      Hi, welcome to Devnet.

      You can use qrc files, even if you build your project with MSVC. The file edition might be more painful, but still feasible. Did you try it, or simply assumed that it was not possible?
      And what about using QtCreator instead? It's really well designed, with tons of shortcuts and features.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        szaman
        wrote on 21 Jan 2016, 20:45 last edited by szaman
        #3

        I read this article but didnt find explanation how to use resources without QtCreator so I assumed that it is impossible.
        Yes I have tried QtCreator it's nice, but I preffer Visual Studio.

        So in steps:
        1. Create .qrc file

        <!DOCTYPE RCC>
        <RCC version="1.0">
        <qresource>
            <file>images/icon.png</file>
        </qresource>
        </RCC>
        

        2. Compile .qrc file

        rcc -binary resource.qrc -o resource.rcc
        

        3. Include compiled .rcc file into executable

        IDB_RES		RCDATA		"resources.rcc"
        

        4. Init resources in main()

        Q_INIT_RESOURCE(IDB_RES);
        

        Do I understand it well?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 21 Jan 2016, 21:01 last edited by mrjj
          #4

          Hi
          Do you use the Qt plugin for Visual Studio ?

          As far as I know it handles the resources for you.
          you could try the
          Diagram Scene Example
          as it has icons for toolbar and see if it just work.
          update:
          http://doc.qt.io/vs-addin/

          1 Reply Last reply
          1
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 21 Jan 2016, 21:18 last edited by
            #5

            There are two ways to use Qt resources.

            1. As an external binary that you load at runtime:

              • create the resource.qrc file
              • compile into a binary: rcc -binary C:/path/to/resource.qrc -o C:/path/to/resource.rcc
              • load at runtime: QResource::registerResource("C:/path/to/resource.rcc");
              • use
            2. As an internal resource compiled into the executable:

              • create the resource.qrc file
              • generate c++ file: rcc -name "someName" -no-compress C:/path/to/resource.qrc -o C:/path/to/resource.cpp
              • include the generated resource.cpp in your solution
              • use

            As @mrjj pointed out the Visual Studio Add-In uses the second method and does the generation and including for you, so all you have to do when you use it is create the qrc file, include it in your solution and that's it.

            O G 2 Replies Last reply 2 Mar 2016, 08:58
            3
            • S Offline
              S Offline
              szaman
              wrote on 21 Jan 2016, 21:29 last edited by
              #6

              @Chris Kawa second options is what I was looking for :) Thanks, solved

              1 Reply Last reply
              0
              • C Chris Kawa
                21 Jan 2016, 21:18

                There are two ways to use Qt resources.

                1. As an external binary that you load at runtime:

                  • create the resource.qrc file
                  • compile into a binary: rcc -binary C:/path/to/resource.qrc -o C:/path/to/resource.rcc
                  • load at runtime: QResource::registerResource("C:/path/to/resource.rcc");
                  • use
                2. As an internal resource compiled into the executable:

                  • create the resource.qrc file
                  • generate c++ file: rcc -name "someName" -no-compress C:/path/to/resource.qrc -o C:/path/to/resource.cpp
                  • include the generated resource.cpp in your solution
                  • use

                As @mrjj pointed out the Visual Studio Add-In uses the second method and does the generation and including for you, so all you have to do when you use it is create the qrc file, include it in your solution and that's it.

                O Offline
                O Offline
                onurA
                wrote on 2 Mar 2016, 08:58 last edited by
                #7

                @Chris-Kawa

                When just adding the images.qrc to resources in pro file, Qt generates a .cpp file when compiling the application out of the images that 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, as you mentioned, 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 the cpp step 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.

                jsulmJ 1 Reply Last reply 2 Mar 2016, 09:37
                0
                • O onurA
                  2 Mar 2016, 08:58

                  @Chris-Kawa

                  When just adding the images.qrc to resources in pro file, Qt generates a .cpp file when compiling the application out of the images that 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, as you mentioned, 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 the cpp step 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.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 2 Mar 2016, 09:37 last edited by
                  #8

                  @onurA This is discussed here: http://forum.qt.io/topic/64734/qt-resource-system/2

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

                  1 Reply Last reply
                  0
                  • C Chris Kawa
                    21 Jan 2016, 21:18

                    There are two ways to use Qt resources.

                    1. As an external binary that you load at runtime:

                      • create the resource.qrc file
                      • compile into a binary: rcc -binary C:/path/to/resource.qrc -o C:/path/to/resource.rcc
                      • load at runtime: QResource::registerResource("C:/path/to/resource.rcc");
                      • use
                    2. As an internal resource compiled into the executable:

                      • create the resource.qrc file
                      • generate c++ file: rcc -name "someName" -no-compress C:/path/to/resource.qrc -o C:/path/to/resource.cpp
                      • include the generated resource.cpp in your solution
                      • use

                    As @mrjj pointed out the Visual Studio Add-In uses the second method and does the generation and including for you, so all you have to do when you use it is create the qrc file, include it in your solution and that's it.

                    G Offline
                    G Offline
                    Gannu Bangalore
                    wrote on 11 Jan 2019, 08:23 last edited by
                    #9

                    @Chris-Kawa Hi Could you pls help me understanding the last point "Use".... I have project which has four .qml files... i have created rcc from qrc...i have loaded .rcc instead of loadin qml...but still i dont know how to use it to display the window which is present in the qml.

                    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