How to access immediate resources imported by qt6_add_resources?
Solved
Qt 6
-
I've written these codes in CMakeLists.txt:
set(TP_IMAGE_FILES ${PROJECT_SOURCE_DIR}/image/icon_Exit.svg ) # TP_ui is the target containing UI codes qt6_add_resources(TP_ui "image" PREFIX "/image" FILES ${TP_IMAGE_FILES} )
However, in cpp files, the file path ":/image/icon_Exit.svg" doesn't exist.
-
Hi,
You can use QDir to go though the content of your resources.
My guess is the the paths you are using to list the files for your resources is appended to your prefix.
-
OK I just checked the directories and files output by the code:
QDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) { qDebug() << it.next(); }
and the file is stored as absolute path.
I changed the related CMake code to
qt6_add_resources(TP_ui "image" PREFIX "/image" BASE "${PROJECT_SOURCE_DIR}/image" FILES ${TP_IMAGE_FILES} )
and solved the problem.