2

How to add qrc file to "QML app with C++ plugin (cmake)" project ? I can't find a working instruction. I found only one thing, add this to CMakeLists.txt:

qt5_add_resources(RESOURCES modules/ProjectName/resources.qrc)

with this the file is finally shown in the files tree in Qt but it's clearly that the file is not included in the executable after compiling so what to do ?

2 Answers2

0
qt5_add_resources(RESOURCES modules/ProjectName/resources.qrc)

That thing converts qrc files into C++ files. Names of C++ files are stored in the RESOURCES variable.

Executables and libraries are compiled from C++ files by using add_executable and add_library in CMakeFiles.txt. In the "QML app with C++ plugin (cmake)" project template the "C++ plugin" part means library. So somewhere in CMakeFiles.txt there is an add_library. Resource files should be added there:

add_library(Myappbackend MODULE
    ${Myappbackend_SRCS}
    ${RESOURCES}
)

Alternatively, the qrc can be compiled directly into separate library by the qt5_add_resources macro or not compiled at all (so no qt5_add_resources at all) and be load by the Qt application in runtime (see source of the core ubuntu-terminal-app for example).

Velkan
  • 3,681
0
set(CMAKE_AUTORCC ON)
add_executable(${PROJECT_NAME} ${SRC_LIST} modules/ProjectName/resources.qrc)
Tim Jenßen
  • 101
  • 2