Problem with loading resources from qrc file
-
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.
-
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
-
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.
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...
-
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.
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...
@SirMarcin Have you enabled
CMAKE_AUTORCC
by addingset(CMAKE_AUTORCC ON)
as the documentation says? -
@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.