Migrating to CMake - adding resource files in Qt Creator
-
I have been working on a migration of a qmake-based project to CMake. I am not very experienced with CMake so bear with me.
I used the migration tool to get me started. The project is not too complicated and that was more or less Ok to get things started.
In the generated CMakeLists.txt file, all my resource files, including QML files were added in a
set(qml_resource_files ...). This worked fine.Later, when syncing my project to other developments, I realised I was missing some new QML files that had been added recently to the qmake project. I added these in Qt Creator using the "Add Existing Files..." option from the project tree. However, I was still seeing runtime errors saying that the QML types I had added were "not a type". This was baffling because the QML files were clearly present in the project tree in the expected locations.
When I examined the CMakeLists.txt, I found that Qt Creator had added the new QML files not to the
qml_resource_filesbut had added them to the file list inqt_add_executable. Not only was this not consistent with what was already being done, but it did not work.Can anyone please explain what is happening here?
In case it is relevant, I have a lot of QML files and they are arranged in a hierarchical directory structure. I use
import "<relative directory path>"in my QML files to make other types available in the current file. -
@JoeCFD said in Migrating to CMake - adding resource files in Qt Creator:
Better to change to meson instead of cmake because cmake is slow.
And how does this solve the problem? Only fud...
-
I have been working on a migration of a qmake-based project to CMake. I am not very experienced with CMake so bear with me.
I used the migration tool to get me started. The project is not too complicated and that was more or less Ok to get things started.
In the generated CMakeLists.txt file, all my resource files, including QML files were added in a
set(qml_resource_files ...). This worked fine.Later, when syncing my project to other developments, I realised I was missing some new QML files that had been added recently to the qmake project. I added these in Qt Creator using the "Add Existing Files..." option from the project tree. However, I was still seeing runtime errors saying that the QML types I had added were "not a type". This was baffling because the QML files were clearly present in the project tree in the expected locations.
When I examined the CMakeLists.txt, I found that Qt Creator had added the new QML files not to the
qml_resource_filesbut had added them to the file list inqt_add_executable. Not only was this not consistent with what was already being done, but it did not work.Can anyone please explain what is happening here?
In case it is relevant, I have a lot of QML files and they are arranged in a hierarchical directory structure. I use
import "<relative directory path>"in my QML files to make other types available in the current file.set(qml_resource_files ...)just assigns multiple files to a CMake variable. It doesn't do anything with the files though.Here is a standard CMake file that adds C++ executable, a QML module and resource files.
cmake_minimum_required(VERSION 3.16) # Not really necessary, but I prefer to set a minimum standard project(MyProject VERSION 0.1 LANGUAGES CXX) # Project name, version and languages set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Quick QuickControls2) qt_standard_project_setup(REQUIRES 6.8) qt_add_executable(appMyProject # adds my main.cpp which then calls QML main.cpp ) qt_add_resources(appMyProject "icons" PREFIX "/" FILES arrow.svg # if you have multiple files, you might want to assign them to a variable ) qt_add_qml_module(appMyProject URI MyProject QML_FILES Main.qml SOURCES qmlextension.h qmlextension.cpp QML_FILES Anotherl.qml QML_FILES EvenMore.qml QML_FILES TheLast.qml ) -
@JoeCFD said in Migrating to CMake - adding resource files in Qt Creator:
Better to change to meson instead of cmake because cmake is slow.
And how does this solve the problem? Only fud...
@Christian-Ehrlicher Do not try to solve the problem. Simply switch to meson. Cmake is messy and slow.
I compared meson and cmake in build of gstreamer. meson is 10 times faster than cmake. Gstreamer has dropped cmake completely.
-
@Christian-Ehrlicher Do not try to solve the problem. Simply switch to meson. Cmake is messy and slow.
I compared meson and cmake in build of gstreamer. meson is 10 times faster than cmake. Gstreamer has dropped cmake completely.
@JoeCFD said in Migrating to CMake - adding resource files in Qt Creator:
@Christian-Ehrlicher Do not try to solve the problem. Simply switch to meson. Cmake is messy and slow.
I compared meson and cmake in build of gstreamer. meson is 10 times faster than cmake. Gstreamer has dropped cmake completely.
Even if true, it's unrelated to the post. It's a random unhelpful statement.