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. Image from resource never shown
Forum Updated to NodeBB v4.3 + New Features

Image from resource never shown

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 5 Posters 757 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.
  • O Offline
    O Offline
    OlivierDz
    wrote on last edited by
    #1

    Hello,
    I have a project (QT 5) with image files put in a resource file.
    The resource file is created with QTCreator.
    When the program is executed from QTCreator, all images are shown correctly.
    When the program is executed ouside QTCreator, the images are not displayed.
    The image files are in the same directory as the resource file.
    The .cpp and .o files corresponding to the resource are created when building the project.
    I put Q_INIT_RESOURCE(images); in the main file.
    Here is an exemple :

        QPixmap pic(":/ok.gif");
        QIcon ic(pic);
        QPushButton* bt = new QPushButton(this);
        bt->setIcon(pic);
    
    

    I also tried to put the full path of ok.gif, but the result is the same.
    I run qmake before building the project.
    I spent some hours on forums and tried a lot a solutions, but with no result actually.
    If somebody has a solution, it will be great.
    Thanks,
    Olivier
    I also try to put the full path

    JonBJ 1 Reply Last reply
    0
    • O OlivierDz

      Hello,
      I have a project (QT 5) with image files put in a resource file.
      The resource file is created with QTCreator.
      When the program is executed from QTCreator, all images are shown correctly.
      When the program is executed ouside QTCreator, the images are not displayed.
      The image files are in the same directory as the resource file.
      The .cpp and .o files corresponding to the resource are created when building the project.
      I put Q_INIT_RESOURCE(images); in the main file.
      Here is an exemple :

          QPixmap pic(":/ok.gif");
          QIcon ic(pic);
          QPushButton* bt = new QPushButton(this);
          bt->setIcon(pic);
      
      

      I also tried to put the full path of ok.gif, but the result is the same.
      I run qmake before building the project.
      I spent some hours on forums and tried a lot a solutions, but with no result actually.
      If somebody has a solution, it will be great.
      Thanks,
      Olivier
      I also try to put the full path

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @OlivierDz
      I am not sure why it would work from within Creator but not outside. I assume you are running the resource compiler to compile the resources into the executable? When run outside, are you executing the same path to the executable as is being used inside Creator?

      Otherwise I would say deploy correctly to use a Qt application outside of Creator, in case there is an issue.

      In your case you should not need Q_INIT_RESOURCE(images);, just (presumably) QPixmap pic(":/images/ok.gif");. Does that make any difference?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mchinand
        wrote on last edited by
        #3

        This could be a plugin issue, specifically the gif plugin to read the image file. How is your application loading the Qt libraries when you run it outside of Qt creator? Have you added it to your path or copied the shared libraries to the same location as your executable?

        O 2 Replies Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          can you please show your qrc file?

          O 1 Reply Last reply
          0
          • M mchinand

            This could be a plugin issue, specifically the gif plugin to read the image file. How is your application loading the Qt libraries when you run it outside of Qt creator? Have you added it to your path or copied the shared libraries to the same location as your executable?

            O Offline
            O Offline
            OlivierDz
            wrote on last edited by
            #5

            @mchinand
            I copied the shared libraries to the same location as my executable.
            I tested with Qt5 and Qt6 / Win 7 and Win 10.
            Here is the list :
            libgcc_s_seh-1.dll
            libstdc++-6.dll
            libwinpthread-1.dll
            Qt6Core.dll
            Qt6Gui.dll
            Qt6PrintSupport.dll
            Qt6Sql.dll
            Qt6Widgets.dll
            platforms/qwindows.dll
            sqldrivers/qsqlite.dll

            Do I miss one ?

            1 Reply Last reply
            0
            • JoeCFDJ JoeCFD

              can you please show your qrc file?

              O Offline
              O Offline
              OlivierDz
              wrote on last edited by
              #6

              @JoeCFD
              Here it is :

              <RCC>
                  <qresource prefix="/">
                      <file>icone.ico</file>
                      <file>icone.png</file>
                      <file>logo_200.jpg</file>
                      <file>logo_2000.png</file>
                      <file>logo_big.png</file>
                      <file>medal.png</file>
                      <file>ok.gif</file>
                      <file>star.gif</file>
                  </qresource>
              </RCC>
              
              
              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                When you want to read a gif file not need the Qt gif plugin in imageformats.

                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
                0
                • M mchinand

                  This could be a plugin issue, specifically the gif plugin to read the image file. How is your application loading the Qt libraries when you run it outside of Qt creator? Have you added it to your path or copied the shared libraries to the same location as your executable?

                  O Offline
                  O Offline
                  OlivierDz
                  wrote on last edited by
                  #8

                  @mchinand
                  You help me to find what was wrong.
                  I forgot to add the "imageformats" libraries (qgif.dll, qico.dll and qjpeg.dll) in the application folder.
                  With this files, its working correctly.
                  Thanks.

                  1 Reply Last reply
                  3

                  • Login

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