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. [Solved] QT Resource File - Images Not Showing When Running

[Solved] QT Resource File - Images Not Showing When Running

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 26.2k 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.
  • N Offline
    N Offline
    nickpost05
    wrote on 29 Jul 2014, 16:10 last edited by
    #1

    I just upgraded to QT Creator 5.3 and created a brand new QT Widgets Application project and am using the Microsoft VC++ compiler. All I have is a resource file with "logo.png" added (which opens in QT if I double click it), and a label that I am trying to set the background image for. The problem is that no matter what I do I cannot get the image to show up when the program is running. The only way I can get it to show the image is by not using the resource file and instead map directly to the file (ex. "c:/blah/blah/logo.png")

    Also, if I set the background image in the UI designer, the background shows up in the IDE but NOT when I run the program. I have tried probably 20+ variations of the code, including resource file aliases as well as adding the files to the project directly, and nothing seems to work.

    I'm not sure if there is a step I am missing, or if perhaps there is something that I have to do to get the project to compile the image.

    Resources.qrc
    @
    <RCC>
    <qresource prefix="/">
    <file>logo.png</file>
    </qresource>
    </RCC>
    @

    loginform.cpp
    @
    ui->setupUi(this);
    QPixmap pixmap = QPixmap (":/logo.png");
    ui->label->setPixmap( pixmap);
    @

    Project.pro
    @
    RESOURCES +=
    Resources.qrc

    SOURCES += main.cpp
    loginform.cpp

    HEADERS += loginform.h

    FORMS += loginform.ui

    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 29 Jul 2014, 16:39 last edited by
      #2

      The only possibility is that logo.png is not found when you are building the project. My suggestion is to delete the resource file, create new resource file and try.

      Can you check whether pixmap is null ? It will be null if pixmap is not created with given image.

      Also you can try with simple example with one just label and png image. This may give you hint.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nickpost05
        wrote on 29 Jul 2014, 17:43 last edited by
        #3

        I put the following code in the project and pixmap is null.
        @
        if (pixmap.isNull())
        MessageBoxA(0,"IS NULL","Error",0);
        @

        I created a new resource file and added the image and it didn't seem to do anything. I also manually edited the resource file to include a file that doesn't exist (logo1.png) and the project built without any errors. Shouldn't it fail it it can't find the file?

        Maybe it has something to do with the VC++ compiler?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Jul 2014, 20:25 last edited by
          #4

          Hi and welcome to devnet,

          Try running qmake when you modify your qrc file. The corresponding C++ file must be regenerated when you modify it.

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • N Offline
            N Offline
            nickpost05
            wrote on 29 Jul 2014, 20:47 last edited by
            #5

            I'm relatively new to QT, and C++ in general, so is that something I have to do with a program outside of QT?

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nickpost05
              wrote on 29 Jul 2014, 23:28 last edited by
              #6

              Ok I think I may have figured it out and it may be the fact that I am a complete noob with QT. There is literally the option to right click on the project and say "run qmake". I did that on my test application and it started displaying the image. I am going to fix up my main app I was working on earlier and see if that same solution fixes that as well. I will let you know the results.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nickpost05
                wrote on 30 Jul 2014, 02:25 last edited by
                #7

                Yep, that was it. Just so everyone is aware of the solution, it was simply to right click the project and click "Run qmake".

                Thanks again to all those who helped!

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 30 Jul 2014, 07:16 last edited by
                  #8

                  You're welcome !

                  Since now you have your qrc file working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  H 1 Reply Last reply 16 Nov 2017, 23:02
                  0
                  • S SGaist
                    30 Jul 2014, 07:16

                    You're welcome !

                    Since now you have your qrc file working, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                    H Offline
                    H Offline
                    Hasan Vaez
                    wrote on 16 Nov 2017, 23:02 last edited by
                    #9

                    @SGaist
                    This problem usually happen when you have two Resource file with same name!(*.qrc).
                    For testing create a main project and create an external library project. Create two res.qrc file with same name.
                    Sometimes you can not see the icons and images on forms or dialogs on the library you have attached to your project. It is rare to see as usually a little number of programmers create a dialog in their LIBS. (for example having your own MESSAGEBOX in an external LIB)
                    I think this is a bug which should be reported to 'qt but report site'

                    regards

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 17 Nov 2017, 20:43 last edited by
                      #10

                      @Hasan-Vaez Not in this case, it was just missing a refresh of the generated code.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 1 Reply Last reply 6 Sept 2018, 12:37
                      0
                      • S SGaist
                        17 Nov 2017, 20:43

                        @Hasan-Vaez Not in this case, it was just missing a refresh of the generated code.

                        S Offline
                        S Offline
                        sayan275
                        wrote on 6 Sept 2018, 12:37 last edited by
                        #11

                        @SGaist Hi,
                        I'm also facing the same issue of resource images not visible when the app is running. I have a plugin-based architecture. Lets say,

                        1. NavControls, a staticLib, in which we have the icons.
                        2. The NavControls lib is used by a Plugin (VIEWERSHARED_EXPORT). I added it in the .pro fo Viewer Plugin
                        //win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../Deploy/bin/release/ -lNavControls
                        else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../Deploy/bin/debug/ -lNavControls
                        
                        INCLUDEPATH += $$PWD/../NavControls
                        DEPENDPATH += $$PWD/../NavControls
                        
                        1. This Viewer plugin implements an Interface.
                        2. Finally, I load the plugin in the app, by QPluginLoader class..

                        The plugin loads without any warnings, but the images are missing on the navControl's buttons.

                        Please suggest what I'm missing!!

                        Thanks,
                        Sayan

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 6 Sept 2018, 12:52 last edited by
                          #12

                          Hi,

                          You likely missed the Using Resources in a Library part of the The Qt Resource System chapter in Qt's documentation.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          S 1 Reply Last reply 14 Sept 2018, 11:43
                          1
                          • S SGaist
                            6 Sept 2018, 12:52

                            Hi,

                            You likely missed the Using Resources in a Library part of the The Qt Resource System chapter in Qt's documentation.

                            S Offline
                            S Offline
                            sayan275
                            wrote on 14 Sept 2018, 11:43 last edited by
                            #13

                            @SGaist Thanks for the suggestion.
                            Sorry for the very delayed reply.
                            I tried few options as in the mentioned link.
                            Adding the qrc path in the application's pro file worked.

                            Thank you!!

                            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