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. Feedback needed: QML is this the right way to link other QML Files?

Feedback needed: QML is this the right way to link other QML Files?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qml c++feedbackcmake
3 Posts 2 Posters 26 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.
  • S Offline
    S Offline
    StudentScripter
    wrote last edited by StudentScripter
    #1

    So my goal was to seperate my .qml files from the Main.qml by creating a subfolder called mymodules/ which contains my other .qml files as a library. But im not sure if my CMakeLists.txt are the most optimal. Can anyone check and give me feeback? <3 Thanks

    My structure looks like this:
    37e1c0a0-c2c0-4867-bb45-d336f08de974-image.png

    mymodules CMakeLists.txt:

    cmake_minimum_required(VERSION 3.16)
    project(mymodules VERSION 1.0 LANGUAGES CXX)
    
    find_package(Qt6 REQUIRED COMPONENTS Quick)
    
    qt_add_library(mymodules STATIC)  # <--- STATIC statt SHARED/PLUGIN
    
    qt_add_qml_module(mymodules
        URI mymodules                 # entspricht: import mymodules 1.0
        VERSION 1.0
        QML_FILES
            Buttons.qml
        RESOURCE_PREFIX /            # wichtig: sonst wird es zur Laufzeit nicht gefunden
    )
    
    target_link_libraries(mymodules
        PRIVATE Qt6::Quick
    )
    

    Main CMakeLists.txt:

    cmake_minimum_required(VERSION 3.16)
    
    project(QmlLibraryTest VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    find_package(Qt6 REQUIRED COMPONENTS Quick)
    
    qt_standard_project_setup(REQUIRES 6.8)
    
    qt_add_executable(appQmlLibraryTest
        main.cpp
    )
    
    qt_add_qml_module(appQmlLibraryTest
        URI QmlLibraryTest
        VERSION 1.0
        QML_FILES
            Main.qml
    )
    
    
    
    
    # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
    # If you are developing for iOS or macOS you should consider setting an
    # explicit, fixed bundle identifier manually though.
    set_target_properties(appQmlLibraryTest PROPERTIES
    #    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appQmlLibraryTest
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    
    
    
    # Baue und installiere das Sub‑Modul mit
    add_subdirectory(mymodules)
    
    
    target_link_libraries(appQmlLibraryTest
        PRIVATE Qt6::Quick
        mymodules  # <-- statische lib (ohne "plugin")
    
    )
    
    include(GNUInstallDirs)
    install(TARGETS appQmlLibraryTest
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    

    main.cpp:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    
    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        QObject::connect
            &engine,
            &QQmlApplicationEngine::objectCreationFailed,
            &app,
            []() { QCoreApplication::exit(-1); },
            Qt::QueuedConnection);
        engine.loadFromModule("QmlLibraryTest", "Main");
    
        return app.exec();
    }
    
    

    @Pl45m4

    Pl45m4P 1 Reply Last reply
    0
    • S StudentScripter

      So my goal was to seperate my .qml files from the Main.qml by creating a subfolder called mymodules/ which contains my other .qml files as a library. But im not sure if my CMakeLists.txt are the most optimal. Can anyone check and give me feeback? <3 Thanks

      My structure looks like this:
      37e1c0a0-c2c0-4867-bb45-d336f08de974-image.png

      mymodules CMakeLists.txt:

      cmake_minimum_required(VERSION 3.16)
      project(mymodules VERSION 1.0 LANGUAGES CXX)
      
      find_package(Qt6 REQUIRED COMPONENTS Quick)
      
      qt_add_library(mymodules STATIC)  # <--- STATIC statt SHARED/PLUGIN
      
      qt_add_qml_module(mymodules
          URI mymodules                 # entspricht: import mymodules 1.0
          VERSION 1.0
          QML_FILES
              Buttons.qml
          RESOURCE_PREFIX /            # wichtig: sonst wird es zur Laufzeit nicht gefunden
      )
      
      target_link_libraries(mymodules
          PRIVATE Qt6::Quick
      )
      

      Main CMakeLists.txt:

      cmake_minimum_required(VERSION 3.16)
      
      project(QmlLibraryTest VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      find_package(Qt6 REQUIRED COMPONENTS Quick)
      
      qt_standard_project_setup(REQUIRES 6.8)
      
      qt_add_executable(appQmlLibraryTest
          main.cpp
      )
      
      qt_add_qml_module(appQmlLibraryTest
          URI QmlLibraryTest
          VERSION 1.0
          QML_FILES
              Main.qml
      )
      
      
      
      
      # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
      # If you are developing for iOS or macOS you should consider setting an
      # explicit, fixed bundle identifier manually though.
      set_target_properties(appQmlLibraryTest PROPERTIES
      #    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appQmlLibraryTest
          MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
          MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
          MACOSX_BUNDLE TRUE
          WIN32_EXECUTABLE TRUE
      )
      
      
      
      
      # Baue und installiere das Sub‑Modul mit
      add_subdirectory(mymodules)
      
      
      target_link_libraries(appQmlLibraryTest
          PRIVATE Qt6::Quick
          mymodules  # <-- statische lib (ohne "plugin")
      
      )
      
      include(GNUInstallDirs)
      install(TARGETS appQmlLibraryTest
          BUNDLE DESTINATION .
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
          RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
      )
      
      

      main.cpp:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          QObject::connect
              &engine,
              &QQmlApplicationEngine::objectCreationFailed,
              &app,
              []() { QCoreApplication::exit(-1); },
              Qt::QueuedConnection);
          engine.loadFromModule("QmlLibraryTest", "Main");
      
          return app.exec();
      }
      
      

      @Pl45m4

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by
      #2

      @StudentScripter

      why you tagged me, I'm not an expert in QML?
      But I would put all qml files in the qt resource system.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      S 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @StudentScripter

        why you tagged me, I'm not an expert in QML?
        But I would put all qml files in the qt resource system.

        S Offline
        S Offline
        StudentScripter
        wrote last edited by
        #3

        @Pl45m4 Thought you'd may have some experience regarding the cmake aspect. :D But nevermind.

        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