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. Using QT .qrc File with Visual Studio Proj…?
Forum Updated to NodeBB v4.3 + New Features

Using QT .qrc File with Visual Studio Proj…?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 2.5k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    AlexanderAlexander
    wrote on 23 Sept 2019, 11:49 last edited by
    #1

    I have a Visual Studio 2017 project that is built with QT and VTK using CMake. I need to use image resources, and wish to use QT's .qrc resource system.

    Information on this seems rare and complex when not using a QT project file. I have found this:

    1. Create a .qrc file that contains a list of the resources you would like to include
    2. Create a custom build step that invokes rcc on that file (documentation)
    3. Compile and link the resulting cpp source file into your program.
      https://stackoverflow.com/questions/56035630/how-to-use-qt-resource-files-in-visual-studio-without-a-qt-project

    I am just completely confused right now on what the proper way to go about this is, and this is not enough information.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 23 Sept 2019, 17:34 last edited by
      #11

      @AlexanderAlexander said in Using QT .qrc File with Visual Studio Proj…?:

      Do you know how to add a resource file in QT Creator's Designer

      No, simply use Qt-Designer, add it there and then it's also available in QtCreator

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply 23 Sept 2019, 18:22
      2
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 23 Sept 2019, 12:23 last edited by
        #2

        Simply add the qrc file to your sources with the help of QT5_ADD_RESOURCES cmake macro

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2
        • A Offline
          A Offline
          AlexanderAlexander
          wrote on 23 Sept 2019, 12:32 last edited by AlexanderAlexander
          #3

          @Christian-Ehrlicher Do I also need to add this to my add_executable in my CMake file (Note: I have Auto RCC on)?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 23 Sept 2019, 12:40 last edited by
            #4

            If you've autorcc on then you don't need the macro: https://cmake.org/cmake/help/latest/manual/cmake-qt.7.html#autorcc

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • A Offline
              A Offline
              AlexanderAlexander
              wrote on 23 Sept 2019, 12:46 last edited by AlexanderAlexander
              #5

              @Christian-Ehrlicher I have built my proj with my new CMake file, and have added my icons images to the qrc file. Within MSCV2017, my QT Addin seems to be working, and I used it to add the resources to the file. Upon building the proj and opening up the solution, I see a qrc_.cpp file generated, and that my images are "in" it (its very complex to me). The only problem is that when I open my UI file with QT Designer, and go to change button icons, nothing is in the resource browser.

              C 1 Reply Last reply 23 Sept 2019, 15:45
              0
              • A AlexanderAlexander
                23 Sept 2019, 12:46

                @Christian-Ehrlicher I have built my proj with my new CMake file, and have added my icons images to the qrc file. Within MSCV2017, my QT Addin seems to be working, and I used it to add the resources to the file. Upon building the proj and opening up the solution, I see a qrc_.cpp file generated, and that my images are "in" it (its very complex to me). The only problem is that when I open my UI file with QT Designer, and go to change button icons, nothing is in the resource browser.

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 23 Sept 2019, 15:45 last edited by
                #6

                You have to add the resource file to your ui file in the designer - the designer and cmake are two completely different things which don't know of each other so the designer also can't know that you added a qrc file to CMakeLists.txt

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                M 1 Reply Last reply 23 Sept 2019, 15:48
                3
                • C Christian Ehrlicher
                  23 Sept 2019, 15:45

                  You have to add the resource file to your ui file in the designer - the designer and cmake are two completely different things which don't know of each other so the designer also can't know that you added a qrc file to CMakeLists.txt

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 23 Sept 2019, 15:48 last edited by
                  #7

                  @Christian-Ehrlicher
                  Hi
                  like this
                  https://doc.qt.io/qt-5/designer-resources.html
                  `?
                  Or is it different when from Visual Studio IDE ?

                  A 1 Reply Last reply 23 Sept 2019, 16:27
                  0
                  • M mrjj
                    23 Sept 2019, 15:48

                    @Christian-Ehrlicher
                    Hi
                    like this
                    https://doc.qt.io/qt-5/designer-resources.html
                    `?
                    Or is it different when from Visual Studio IDE ?

                    A Offline
                    A Offline
                    AlexanderAlexander
                    wrote on 23 Sept 2019, 16:27 last edited by AlexanderAlexander
                    #8

                    @Christian-Ehrlicher To clarify, I am in QT Creator's embedded Design mode. How would I add the resource file from there, the only thing to do with resources that I can open is when I edit the icon property of an item. It just opens up the "Choose Resource" Window, and there is just <resource root>. I cant edit a pathway or add a file...?

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 23 Sept 2019, 16:48 last edited by
                      #9

                      @AlexanderAlexander said in Using QT .qrc File with Visual Studio Proj…?:

                      I am in QT Creator's embedded Design mode

                      Previously your said you're using MSVC2017 + Qt Vs Addin and using Qt designer

                      Within MSCV2017, my QT Addin seems to be working ... I open my UI file with QT Designer

                      In Qt designer you can add a resource file in the resource editor dock widget.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      A 1 Reply Last reply 23 Sept 2019, 17:04
                      2
                      • C Christian Ehrlicher
                        23 Sept 2019, 16:48

                        @AlexanderAlexander said in Using QT .qrc File with Visual Studio Proj…?:

                        I am in QT Creator's embedded Design mode

                        Previously your said you're using MSVC2017 + Qt Vs Addin and using Qt designer

                        Within MSCV2017, my QT Addin seems to be working ... I open my UI file with QT Designer

                        In Qt designer you can add a resource file in the resource editor dock widget.

                        A Offline
                        A Offline
                        AlexanderAlexander
                        wrote on 23 Sept 2019, 17:04 last edited by
                        #10

                        @Christian-Ehrlicher My apologies for the confusion, I always call it that by accident. Do you know how to add a resource file in QT Creator's Designer. I can't find any documentation on how to do so...

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on 23 Sept 2019, 17:34 last edited by
                          #11

                          @AlexanderAlexander said in Using QT .qrc File with Visual Studio Proj…?:

                          Do you know how to add a resource file in QT Creator's Designer

                          No, simply use Qt-Designer, add it there and then it's also available in QtCreator

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          A 1 Reply Last reply 23 Sept 2019, 18:22
                          2
                          • C Christian Ehrlicher
                            23 Sept 2019, 17:34

                            @AlexanderAlexander said in Using QT .qrc File with Visual Studio Proj…?:

                            Do you know how to add a resource file in QT Creator's Designer

                            No, simply use Qt-Designer, add it there and then it's also available in QtCreator

                            A Offline
                            A Offline
                            AlexanderAlexander
                            wrote on 23 Sept 2019, 18:22 last edited by
                            #12

                            @Christian-Ehrlicher I can't believe I never thought of doing that. It's finally working now. Thank you so much for the help and sorry about all of my confusion.

                            1 Reply Last reply
                            0

                            1/12

                            23 Sept 2019, 11:49

                            • Login

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