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
Forum Updated to NodeBB v4.3 + New Features

Cannot display image from .qrc file cmake

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 321 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 28 Apr 2024, 17:03 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!

    C 1 Reply Last reply 28 Apr 2024, 17:13
    0
    • M markovvv
      28 Apr 2024, 17:03

      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!

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 28 Apr 2024, 17:13 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 28 Apr 2024, 17:17
      0
      • C Christian Ehrlicher
        28 Apr 2024, 17:13

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

        M Offline
        M Offline
        markovvv
        wrote on 28 Apr 2024, 17:17 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>
        
        
        C 1 Reply Last reply 28 Apr 2024, 17:22
        0
        • M markovvv
          28 Apr 2024, 17:17

          @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>
          
          
          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 28 Apr 2024, 17:22 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 28 Apr 2024, 17:28
          2
          • C Christian Ehrlicher
            28 Apr 2024, 17:22

            @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 28 Apr 2024, 17:28 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 28 Apr 2024, 17:29

            1/5

            28 Apr 2024, 17:03

            • Login

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