create Qml sub modules
-
I’m trying to create a QML module named ERP, with a submodule ERP.Singletons that contains a singleton QML file (ColorPalette.qml).
However, when I run the application, I get the following error:qrc:/qt/qml/ERP/qml/Main.qml:3:1: module "ERP.Singletons" is not installedproject structure:
. ├── CMakeLists.txt ├── CMakeLists.txt.user ├── qml │ ├── Main.qml │ └── singleton │ └── ColorPalette.qml └── source └── main.cppCMakeLists.txt
cmake_minimum_required(VERSION 3.16) project(ERP VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Quick) qt_standard_project_setup(REQUIRES 6.8) qt_add_executable(appERP source/main.cpp ) qt_add_qml_module(appERP URI ERP VERSION 1.0 QML_FILES qml/Main.qml ) set_source_files_properties( qml/singleton/ColorPalette.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE ) qt_add_qml_module(ERP_Singletons URI ERP.Singletons VERSION 1.0 QML_FILES qml/singleton/ColorPalette.qml ) set_target_properties(appERP PROPERTIES MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} ) target_link_libraries(appERP PRIVATE Qt6::Quick ERP_Singletons ) include(GNUInstallDirs) install(TARGETS appERP BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )QML Files
Main.qml:import QtQuick import QtQuick.Controls import ERP.Singletons ApplicationWindow { width: 640 height: 480 visible: true title: "ERP" color: ColorPalette.background }ColorPalatte.qml:
pragma Singleton import QtQuick QtObject { property color background: "#333333" property color text: "#ffffff" }Binary Tree:
build/ ├── appERP ├── ERP/ │ ├── qml/ │ │ ├── Main.qml │ │ └── qmldir │ └── qmldir ├── ERP_Singletons.qmltypes ├── libERP_Singletons.so ├── libERP_Singletonsplugin.so └── qml/ └── singleton/ ├── ColorPalette.qml └── qmldir