cmake qmldir automatic and manual problem
-
Two questions:
-
cmake automatically generates qmldir, when I have qml files of the same name in different folders, how should I set this time?
-
If I turn off cmake and import qmldir manually, qtcreator's qml model does not recognize the corresponding qml code; however, the program still runs successfully.
eg.
this is my example code
/*------------------model/Style.qml--------------------------------*/ pragma Singleton import QtQuick QtObject { id: styleRoot // Color Configurations For Skins readonly property string colorConfigs: "11231243124" readonly property string hmiFontPaddingBottom: "你是来搞笑的吗" } /*--------------------main.qml-----------------------------------*/ import QtQuick import QtQuick.Window import model 1.0 Window { width: 640 height: 480 visible: true title: Style.hmiFontPaddingBottom } /********cmakeLists.txt****************/ cmake_minimum_required(VERSION 3.16) project(tttt VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.4 REQUIRED COMPONENTS Quick) qt_standard_project_setup() #遍历所有qml文件 file(GLOB_RECURSE QML_PATHS *.qml) foreach(filepath ${QML_PATHS}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) list(APPEND qml_files ${filename}) endforeach(filepath) qt_add_executable(apptttt main.cpp ) qt_add_qml_module(apptttt URI tttt VERSION 1.0 QML_FILES ${qml_files} IMPORT_PATH "../tttt/" NO_GENERATE_QMLTYPES NO_GENERATE_QMLDIR ) set_target_properties(apptttt PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(apptttt PRIVATE Qt6::Quick ) install(TARGETS apptttt BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
-
-
Two questions:
-
cmake automatically generates qmldir, when I have qml files of the same name in different folders, how should I set this time?
-
If I turn off cmake and import qmldir manually, qtcreator's qml model does not recognize the corresponding qml code; however, the program still runs successfully.
eg.
this is my example code
/*------------------model/Style.qml--------------------------------*/ pragma Singleton import QtQuick QtObject { id: styleRoot // Color Configurations For Skins readonly property string colorConfigs: "11231243124" readonly property string hmiFontPaddingBottom: "你是来搞笑的吗" } /*--------------------main.qml-----------------------------------*/ import QtQuick import QtQuick.Window import model 1.0 Window { width: 640 height: 480 visible: true title: Style.hmiFontPaddingBottom } /********cmakeLists.txt****************/ cmake_minimum_required(VERSION 3.16) project(tttt VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.4 REQUIRED COMPONENTS Quick) qt_standard_project_setup() #遍历所有qml文件 file(GLOB_RECURSE QML_PATHS *.qml) foreach(filepath ${QML_PATHS}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" filename ${filepath}) list(APPEND qml_files ${filename}) endforeach(filepath) qt_add_executable(apptttt main.cpp ) qt_add_qml_module(apptttt URI tttt VERSION 1.0 QML_FILES ${qml_files} IMPORT_PATH "../tttt/" NO_GENERATE_QMLTYPES NO_GENERATE_QMLDIR ) set_target_properties(apptttt PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(apptttt PRIVATE Qt6::Quick ) install(TARGETS apptttt BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
@Jian5 Maybe you can use qrc files to store all qml files.
- The same qml files in different dirs can be defined with different names or prefix via alias.
- no more issues in Qt Creator with qrc files.
https://forum.qt.io/topic/145193/qml-loader-local-qml-file-access-to-qrc-component/4?_=1684857962389
-