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. cmake qmldir automatic and manual problem
Forum Updated to NodeBB v4.3 + New Features

cmake qmldir automatic and manual problem

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 604 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.
  • J Offline
    J Offline
    Jian5
    wrote on last edited by
    #1

    Two questions:

    1. cmake automatically generates qmldir, when I have qml files of the same name in different folders, how should I set this time?

    2. 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. 0ea5c1c6-0f13-4948-985a-46c410c442f2-image.png

    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})
    
    JoeCFDJ 1 Reply Last reply
    0
    • J Jian5

      Two questions:

      1. cmake automatically generates qmldir, when I have qml files of the same name in different folders, how should I set this time?

      2. 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. 0ea5c1c6-0f13-4948-985a-46c410c442f2-image.png

      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})
      
      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @Jian5 Maybe you can use qrc files to store all qml files.

      1. The same qml files in different dirs can be defined with different names or prefix via alias.
      2. 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

      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