qt_add_resources not adding resources
-
Hi all,
I hope someone with real insight of all that can explain this to me.
I recently got a merge request for KGeoTag fixing a startup crash. The problem was that KGeoTag uses KDE's KXmlGui classes, and it needs a definition file to be present (
kgeotagui.rcin this case), otherwise, it will crash when starting. Said file was bundled via Qt's resource system.I recently dropped Qt5/KF5 support and reworked my CMakeLists.txt sources management a bit: Instead of having multiple variables containing all source files, I now first define a target like that:
add_executable(kgeotag)and then I add the sources directory containing all source files and an own CMakeLists.txt file like that:
add_subdirectory(src)Inside
src/, the sources definition looks like this:target_sources(kgeotag PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/AutomaticMatchingWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/AutomaticMatchingWidget.h ${CMAKE_CURRENT_SOURCE_DIR}/BookmarksList.cpp ${CMAKE_CURRENT_SOURCE_DIR}/BookmarksList.h ... )However, adding said resource file seems not to work anymore using this setup. Until now, I used
qt_add_resources(kgeotag ${CMAKE_SOURCE_DIR}/kgeotag.qrc)With
kgeotag.qrcbeing:<RCC version="1.0"> <qresource prefix="/kxmlgui5/kgeotag"> <file>kgeotagui.rc</file> </qresource> </RCC>But
kgeotagui.rcis actually not included, no matter where I put the macro. And the program crashes on startup, due to the file being not present.However, if I don't use
qt_add_resourcesbut addkgeotag.qrcto the sources list like that:target_sources(kgeotag PRIVATE ${CMAKE_SOURCE_DIR}/kgeotag.qrc )in the top-level CMakeLists.txt (cf. the corresponding patch), the rc file is added like it should and the program's startup runs as expected.
So: Why does
qt_add_resourcesnot work anymore here? -
Hi,
From a quick look at the qt_add_resources documentation:
set(sources main.cpp) qt_add_resources(sources example.qrc) qt_add_executable(myapp ${sources})It seems that
qt_add_resources, in the context of a qrc file, should be called with a variable containing the list of files for your executable. -
perhaps you could add this to the cmake file?
set(CMAKE_AUTORCC ON) -
perhaps you could add this to the cmake file?
set(CMAKE_AUTORCC ON)@l3u_ said in qt_add_resources not adding resources:
qt_add_resources(kgeotag ${CMAKE_SOURCE_DIR}/kgeotag.qrc)With
kgeotag.qrcbeing:<RCC version="1.0"> <qresource prefix="/kxmlgui5/kgeotag"> <file>kgeotagui.rc</file> </qresource> </RCC>I believe what you want is (replace "MyResources" with whatever name you like):
qt_add_resources(kgeotag "MyResources" PREFIX "/kxmlgui5/kgeotag" FILES ${CMAKE_SOURCE_DIR}/kgeotagui.rc )The *.qrc file is redundant.
Anyway, when troubleshooting resource issues, try the following snippet:
QDirIterator qrc(":", QDirIterator::Subdirectories); while(qrc.hasNext()) qDebug() << qrc.next();@MalcolmSequeira said in qt_add_resources not adding resources:
perhaps you could add this to the cmake file?
set(CMAKE_AUTORCC ON)The target-based
qt_add_resources()replaces CMAKE_AUTORCC. CMAKE_AUTORCC should not be used anymore: https://bugreports.qt.io/browse/QTBUG-87643 -
Hi,
From a quick look at the qt_add_resources documentation:
set(sources main.cpp) qt_add_resources(sources example.qrc) qt_add_executable(myapp ${sources})It seems that
qt_add_resources, in the context of a qrc file, should be called with a variable containing the list of files for your executable.@SGaist said in qt_add_resources not adding resources:
Hi,
From a quick look at the qt_add_resources documentation:
set(sources main.cpp) qt_add_resources(sources example.qrc) qt_add_executable(myapp ${sources})It seems that
qt_add_resources, in the context of a qrc file, should be called with a variable containing the list of files for your executable.So the core issue is that I can define my sources via
target_sources, but this won't work withqt_add_resources, as this one only works with a (classic) list of files, and not withtarget_sources?