Issue with Qt6 QML Module Target Path and CMake Warning
-
I'm working on a Qt6 project where I'm trying to add multiple QML modules. I am encountering a warning when using the qt_add_qml_module macro for the TelemetorQmlControlsModule target. Here's the warning I'm receiving:
CMake Warning at /home/hyaldiz/Qt/6.4.2/gcc_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:770 (message):
The TelemetorQmlControlsModule target is a QML module with target path
Telemetor/Controls. It uses an OUTPUT_DIRECTORY of
/home/hyaldiz/Desktop/Personal/Telemetor/build/Desktop_6_4_2-Debug/src/QmlControls,
which should end in the same target path, but doesn't. Tooling such as
cmake qmllint may not work correctly.Project Setup:
QmlControls Cmake:
target_sources(${CMAKE_PROJECT_NAME}
PRIVATE
TPalette.hpp
TPalette.cpp
QmlGlobal.hpp
QmlGlobal.cpp
)target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
qt_add_library(TelemetorQmlControlsModule STATIC)
set_source_files_properties(ScreenTools.qml
PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)qt_add_qml_module(TelemetorQmlControlsModule
URI Telemetor.Controls
VERSION 1.0
RESOURCE_PREFIX /qml
QML_FILES
TMenuBar.qml
TMenu.qml
TLabel.qml
ScreenTools.qml
NO_PLUGIN
)UI Cmake:
qt_add_library(MainWindowModule STATIC)qt_add_qml_module(MainWindowModule
URI Telemetor.MainWindow
VERSION 1.0
RESOURCE_PREFIX /qml
QML_FILES
MainWindow.qml
NO_PLUGIN
)Src CMake:
qt_add_library(TelemetorModule STATIC)qt_add_qml_module(TelemetorModule
URI Telemetor
VERSION 1.0
RESOURCE_PREFIX /qml
IMPORTS
TM
NO_PLUGIN
)add_subdirectory(UI)
add_subdirectory(API)
add_subdirectory(QmlControls)target_sources(${CMAKE_PROJECT_NAME}
PRIVATE
main.cpp
Application.hpp
Application_p.hpp
Application.cpp
AppMessages.hpp
AppMessages.cpp
)target_include_directories(${CMAKE_PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR})target_link_libraries(${CMAKE_PROJECT_NAME}
PRIVATE
Qt6::Core
Qt6::Widgets
Qt6::Gui
Qt6::Concurrent
Qt6::Qml
Qt6::QmlIntegration
Qt6::QuickControls2
Qt6::QuickWidgets
Qt6::Quick
MainWindowModule
TelemetorModule
TelemetorQmlControlsModule
#ScreenToolsModule
)set_target_properties(${CMAKE_PROJECT_NAME}
PROPERTIES
QT_RESOURCE_PREFIX "/qml"
OUTPUT_NAME ${CMAKE_PROJECT_NAME}
)Root Cmake:
cmake_minimum_required(VERSION 3.25)list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake
${CMAKE_SOURCE_DIR}/cmake/modules
)include(Toolchain)
include(CustomOptions)
include(Git)project(${APP_NAME}
VERSION ${APP_VERSION}
DESCRIPTION ${APP_DESCRIPTION}
LANGUAGES C CXX
)find_package(Qt6
REQUIRED
COMPONENTS
Core
Gui
Widgets
Concurrent
Qml
QmlIntegration
QuickControls2
QuickWidgets
Quick
)qt_add_executable(${CMAKE_PROJECT_NAME}
#RESOURCES
)qt_add_qml_module(${CMAKE_PROJECT_NAME}
URI TM
VERSION 1.0
RESOURCE_PREFIX /qml
IMPORTS
QtQuick
QtQuick.Controls
QtQuick.Dialogs
QtQuick.Layouts
QtQuick.Window
)add_subdirectory(src)
The Issue:
-
The warning suggests that the OUTPUT_DIRECTORY (/home/hyaldiz/Desktop/Personal/Telemetor/build/Desktop_6_4_2-Debug/src/QmlControls) doesn't match the target path (Telemetor/Controls), which might cause issues with tools like qmllint.
-
Additionally, even though the import statement in MainWindow.qml like import Telemetor.Controls doesn't seem to be recognized by Qt Creator, the code works as expected.
Question:
-
How can I resolve this warning and make sure the OUTPUT_DIRECTORY ends in the same path as the QML target path?
-
Why is import Telemetor.Controls not being recognized by Qt Creator, even though the code works fine at runtime?
Any advice on how to fix this issue would be appreciated!
-
-
CMake Warning at /home/hyaldiz/Qt/6.4.2/gcc_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:770 (message): The TelemetorQmlControlsModule target is a QML module with target path Telemetor/Controls. It uses an OUTPUT_DIRECTORY of /home/hyaldiz/Desktop/Personal/Telemetor/build/Desktop_6_4_2-Debug/src/QmlControls,The path in which your plugin is located inside your project structure ends with QmlControls.
You must adjust it to be Telemetor/Controls. -
I'm working on a Qt6 project where I'm trying to add multiple QML modules. I am encountering a warning when using the qt_add_qml_module macro for the TelemetorQmlControlsModule target. Here's the warning I'm receiving:
CMake Warning at /home/hyaldiz/Qt/6.4.2/gcc_64/lib/cmake/Qt6Qml/Qt6QmlMacros.cmake:770 (message):
The TelemetorQmlControlsModule target is a QML module with target path
Telemetor/Controls. It uses an OUTPUT_DIRECTORY of
/home/hyaldiz/Desktop/Personal/Telemetor/build/Desktop_6_4_2-Debug/src/QmlControls,
which should end in the same target path, but doesn't. Tooling such as
cmake qmllint may not work correctly.Project Setup:
QmlControls Cmake:
target_sources(${CMAKE_PROJECT_NAME}
PRIVATE
TPalette.hpp
TPalette.cpp
QmlGlobal.hpp
QmlGlobal.cpp
)target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
qt_add_library(TelemetorQmlControlsModule STATIC)
set_source_files_properties(ScreenTools.qml
PROPERTIES
QT_QML_SINGLETON_TYPE TRUE
)qt_add_qml_module(TelemetorQmlControlsModule
URI Telemetor.Controls
VERSION 1.0
RESOURCE_PREFIX /qml
QML_FILES
TMenuBar.qml
TMenu.qml
TLabel.qml
ScreenTools.qml
NO_PLUGIN
)UI Cmake:
qt_add_library(MainWindowModule STATIC)qt_add_qml_module(MainWindowModule
URI Telemetor.MainWindow
VERSION 1.0
RESOURCE_PREFIX /qml
QML_FILES
MainWindow.qml
NO_PLUGIN
)Src CMake:
qt_add_library(TelemetorModule STATIC)qt_add_qml_module(TelemetorModule
URI Telemetor
VERSION 1.0
RESOURCE_PREFIX /qml
IMPORTS
TM
NO_PLUGIN
)add_subdirectory(UI)
add_subdirectory(API)
add_subdirectory(QmlControls)target_sources(${CMAKE_PROJECT_NAME}
PRIVATE
main.cpp
Application.hpp
Application_p.hpp
Application.cpp
AppMessages.hpp
AppMessages.cpp
)target_include_directories(${CMAKE_PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR})target_link_libraries(${CMAKE_PROJECT_NAME}
PRIVATE
Qt6::Core
Qt6::Widgets
Qt6::Gui
Qt6::Concurrent
Qt6::Qml
Qt6::QmlIntegration
Qt6::QuickControls2
Qt6::QuickWidgets
Qt6::Quick
MainWindowModule
TelemetorModule
TelemetorQmlControlsModule
#ScreenToolsModule
)set_target_properties(${CMAKE_PROJECT_NAME}
PROPERTIES
QT_RESOURCE_PREFIX "/qml"
OUTPUT_NAME ${CMAKE_PROJECT_NAME}
)Root Cmake:
cmake_minimum_required(VERSION 3.25)list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake
${CMAKE_SOURCE_DIR}/cmake/modules
)include(Toolchain)
include(CustomOptions)
include(Git)project(${APP_NAME}
VERSION ${APP_VERSION}
DESCRIPTION ${APP_DESCRIPTION}
LANGUAGES C CXX
)find_package(Qt6
REQUIRED
COMPONENTS
Core
Gui
Widgets
Concurrent
Qml
QmlIntegration
QuickControls2
QuickWidgets
Quick
)qt_add_executable(${CMAKE_PROJECT_NAME}
#RESOURCES
)qt_add_qml_module(${CMAKE_PROJECT_NAME}
URI TM
VERSION 1.0
RESOURCE_PREFIX /qml
IMPORTS
QtQuick
QtQuick.Controls
QtQuick.Dialogs
QtQuick.Layouts
QtQuick.Window
)add_subdirectory(src)
The Issue:
-
The warning suggests that the OUTPUT_DIRECTORY (/home/hyaldiz/Desktop/Personal/Telemetor/build/Desktop_6_4_2-Debug/src/QmlControls) doesn't match the target path (Telemetor/Controls), which might cause issues with tools like qmllint.
-
Additionally, even though the import statement in MainWindow.qml like import Telemetor.Controls doesn't seem to be recognized by Qt Creator, the code works as expected.
Question:
-
How can I resolve this warning and make sure the OUTPUT_DIRECTORY ends in the same path as the QML target path?
-
Why is import Telemetor.Controls not being recognized by Qt Creator, even though the code works fine at runtime?
Any advice on how to fix this issue would be appreciated!
@Yaldiz said in Issue with Qt6 QML Module Target Path and CMake Warning:
How can I resolve this warning and make sure the OUTPUT_DIRECTORY ends in the same path as the QML target path?
By ensuring that your source files' path matches the URI. For example, if the URI is
Telemetor.Controlsthen the source path should be like${CMAKE_SOURCE_DIR}/Telemotor/Controls/TMenuBar.qmlWhy is import Telemetor.Controls not being recognized by Qt Creator, even though the code works fine at runtime?
Because the runtime engine loads the modules from the resource files that are embedded inside your executable -- these have the correct paths. However, Qt Creator cannot see the files that are embedded inside your executable, so it must load them from disk.
So if you get the warning that OUTPUT_DIRECTORY doesn't match the target path, that means Qt Creator won't be able to find the files at the expected paths on disk.
-