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. Problem with loading resources from qrc file
QtWS25 Last Chance

Problem with loading resources from qrc file

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 196 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.
  • S Offline
    S Offline
    SirMarcin
    wrote on last edited by
    #1

    I have a problem with adding images to the program. I have added files to resources.qrc, I can see them when I add them in the .ui file, I can see their preview in the .cpp file for example - QPixmap backgroundPixmap(":/background.png"); but at the same time when compiling I get the message: "Could not create pixmap from :\background.png
    Could not create pixmap from :\images.png" I have tried everything and the problem is still the same. I also tried the project with just loading the file and it was the same. I have no idea why the program sees the photos but not during compilation.
    ede96aca-c73a-4005-bada-826d6917fc1b-image.png
    9c6afe70-0ede-4a37-83bb-9c5a0214d7d7-image.png

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Take a look how the directory structure in the qrc really looks like:

       QDirIterator it(":");
       while (it.hasNext())
           qDebug() << it.next();
      

      See https://doc.qt.io/qt-6/qdiriterator.html#details for further usage of QDirIterator

      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
      • S Offline
        S Offline
        SirMarcin
        wrote on last edited by
        #3

        Thank you for your answer, unfortunately, the program does not find the resources, even though they are added in the resources.qrc file and they are visible in QtCreator and Design.

        image.png

        I don't put the whole list of resources, because there are also QtCreator resources above, mine are only i18n, there are none from the qrc file, there are only with translations that are not in my .qrc I add the .qrc file in cpp in qt_add_executable, so it should appear in the list of resources. I don't know why this is happening...

        8f4a84c5-a9c3-4bdf-9c6e-813e7bcc1184-image.png

        B 1 Reply Last reply
        0
        • S SirMarcin

          Thank you for your answer, unfortunately, the program does not find the resources, even though they are added in the resources.qrc file and they are visible in QtCreator and Design.

          image.png

          I don't put the whole list of resources, because there are also QtCreator resources above, mine are only i18n, there are none from the qrc file, there are only with translations that are not in my .qrc I add the .qrc file in cpp in qt_add_executable, so it should appear in the list of resources. I don't know why this is happening...

          8f4a84c5-a9c3-4bdf-9c6e-813e7bcc1184-image.png

          B Offline
          B Offline
          Bonnie
          wrote on last edited by
          #4

          @SirMarcin Have you enabled CMAKE_AUTORCC by adding set(CMAKE_AUTORCC ON) as the documentation says?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Colins2
            wrote on last edited by
            #5

            @SirMarcin
            As Bonnie says. I had this problem while doing a course at least a year ago now. It turned out that the template was incomplete for the version of Qt I had installed. The previous version worked fine so I was able to copy the template from an older version and then it all worked.

            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