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. Cannot display image from .qrc file cmake

Cannot display image from .qrc file cmake

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 319 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.
  • M Offline
    M Offline
    markovvv
    wrote on last edited by
    #1

    Hello guys, i cannot display images from .qrc file

    my CMakeLists.txt:

    set(CMAKE_AUTORCC ON)
    set(QRC_FILES
        "${QRC_FILES_PATH}/shaders.qrc"
        "${QRC_FILES_PATH}/images.qrc"
    )
    qt_add_resources(RESOURCE_FILES ${QRC_FILES})
    qt_add_executable(${PROJECT_NAME} ${SOURCES} ${INCLUDES} ${UI} ${RESOURCE_FILES})
    

    .qrc files are found(they are displayed on left at the menu, even with all .pngs), but i cannot pick them up for example like that:

    QPixmap gamePixmap(":/headingConflicts.png");
    

    But if i do that with the full path:

    QPixmap gamePixmap("/xxxx/xxxx/work/mywork/xxxx/xxxx/xxxx/share/img/games/headingConflicts.png");
    
    

    its working fine.
    Does anybody know where could be a problem?
    Thanks!

    Christian EhrlicherC 1 Reply Last reply
    0
    • M markovvv

      Hello guys, i cannot display images from .qrc file

      my CMakeLists.txt:

      set(CMAKE_AUTORCC ON)
      set(QRC_FILES
          "${QRC_FILES_PATH}/shaders.qrc"
          "${QRC_FILES_PATH}/images.qrc"
      )
      qt_add_resources(RESOURCE_FILES ${QRC_FILES})
      qt_add_executable(${PROJECT_NAME} ${SOURCES} ${INCLUDES} ${UI} ${RESOURCE_FILES})
      

      .qrc files are found(they are displayed on left at the menu, even with all .pngs), but i cannot pick them up for example like that:

      QPixmap gamePixmap(":/headingConflicts.png");
      

      But if i do that with the full path:

      QPixmap gamePixmap("/xxxx/xxxx/work/mywork/xxxx/xxxx/xxxx/share/img/games/headingConflicts.png");
      
      

      its working fine.
      Does anybody know where could be a problem?
      Thanks!

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please show the qrc file. I would guess there is a prefix defined for the files.

      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
      0
      • Christian EhrlicherC Christian Ehrlicher

        Please show the qrc file. I would guess there is a prefix defined for the files.

        M Offline
        M Offline
        markovvv
        wrote on last edited by
        #3

        @Christian-Ehrlicher Hey, thanks for reply. Here is the .qrc file:

        <RCC>
            <qresource prefix="/">
                <file>../share/img/ui/statsbtn.png</file>
                <file>../share/img/games/headingConflicts.png</file>
                <file>../share/img/ui/infobtn.png</file>
                <file>../share/img/ui/playbtn.png</file>
                <file>../share/img/ui/statsbtn2.png</file>
            </qresource>
        </RCC>
        
        
        Christian EhrlicherC 1 Reply Last reply
        0
        • M markovvv

          @Christian-Ehrlicher Hey, thanks for reply. Here is the .qrc file:

          <RCC>
              <qresource prefix="/">
                  <file>../share/img/ui/statsbtn.png</file>
                  <file>../share/img/games/headingConflicts.png</file>
                  <file>../share/img/ui/infobtn.png</file>
                  <file>../share/img/ui/playbtn.png</file>
                  <file>../share/img/ui/statsbtn2.png</file>
              </qresource>
          </RCC>
          
          
          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @markovvv said in Cannot display image from .qrc file cmake:

          share/img/games/headingConflicts.png

          So it should be :/share/img/games/headingConflicts.png I would guess. I also would not place a qrc file in another sub-directory than the files.

          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
          2
          • Christian EhrlicherC Christian Ehrlicher

            @markovvv said in Cannot display image from .qrc file cmake:

            share/img/games/headingConflicts.png

            So it should be :/share/img/games/headingConflicts.png I would guess. I also would not place a qrc file in another sub-directory than the files.

            M Offline
            M Offline
            markovvv
            wrote on last edited by
            #5

            @Christian-Ehrlicher Its working now. Thanks very much!

            1 Reply Last reply
            0
            • M markovvv has marked this topic as solved on

            • Login

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