unable to show pixmap using qrc file
-
I have added an image to a qrc file, and want to show it instead of using the absolute path, but it doesnt seem to want to work no matter what I try. Using the absolute path works fine but trying to reference the qrc doesnt work at all.
the project file structure is like this:└── zzz-optimizer/ ├── window.h ├── window.ui ├── main.cpp ├── assets.qrc ├── window.cpp ├── CMakeLists.txt └── assets/ └── discs/ └── DawnsBloom.png
The qrc looks like this:
<RCC> <qresource prefix="/discs"> <file alias="DawnsBloom.png">assets/discs/DawnsBloom.png</file> </qresource> </RCC>
In qt designer, it shows up just fine, but the actual application shows nothing (designer vs build):
how can i make this work?
-
Do you add the qrc to your executable? Also which path do you use for the image? It's
:/discs/DawnsBloom.png
-
@yav12 said in unable to show pixmap using qrc file:
he qrc is referenced in the cmakelists.txt
Please show the CMakeLists.txt
Also look what's really inside your qrc during runtime withQDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) qDebug() << it.next();
-
my cmakelists.txt looks like this:
cmake_minimum_required(VERSION 3.19) project(zzz-optimizer LANGUAGES CXX) find_package(Qt6 6.5 REQUIRED COMPONENTS Core Widgets) qt_standard_project_setup() qt_add_executable(zzz-optimizer WIN32 MACOSX_BUNDLE main.cpp window.cpp window.h window.ui assets.qrc ) target_link_libraries(zzz-optimizer PRIVATE Qt::Core Qt::Widgets ) include(GNUInstallDirs) install(TARGETS zzz-optimizer BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_generate_deploy_app_script( TARGET zzz-optimizer OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script})
Also look what's really inside your qrc
i placed this code in, and a LOT of files showed up (it took a couple minutes to finish printing everything) but not my file in the qrc
-