Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. create Qml sub modules
Forum Updated to NodeBB v4.3 + New Features

create Qml sub modules

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 110 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmirCH81
    wrote on last edited by
    #1

    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 installed
    

    project structure:

    .
    ├── CMakeLists.txt
    ├── CMakeLists.txt.user
    ├── qml
    │   ├── Main.qml
    │   └── singleton
    │       └── ColorPalette.qml
    └── source
        └── main.cpp
    

    CMakeLists.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
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved