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 and importing QML files
Qt 6.11 is out! See what's new in the release blog

CMake and importing QML files

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 138 Views 1 Watching
  • 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.
  • O Offline
    O Offline
    Oen44
    wrote last edited by Oen44
    #1

    Hi,

    I'm trying to figure out a way to have importing work in a more dynamic way than throwing every single .qml file and folder into CMakeLists.txt.

    Example project structure:

    project/
    ├── src/
    │   └── main.cpp
    └── ui/
        ├── panels/
        │   └── RoundedPanel.qml
        ├── buttons/
        │   ├── Button.qml
        │   └── RoundedButton.qml
        └── root.qml
    

    Results in:

    import ui.panels
    RounedPanel {  }
    
    import ui.buttons
    Button { }
    RoundedButton { }
    

    The catch here is that if at any point I would create new directory in ui and add new .qml there, it should automatically work (even if after build/reconfiguring CMake).

    So far I only came across qmldir (which didn't even work for me) and qt_add_qml_module but that requires manually adding new qml files.

    Any suggestions?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bob64
      wrote last edited by
      #2

      I believe globbing is supported by CMake but that it is generally recommended not to use it. As a CMake newbie myself I have followed what seemed to be the prevailing wisdom and stuck to hard coded lists.

      One compromise that I did come across was to read the file list from an external file, e.g., file(STRINGS "sources_list.txt" MYSRCS) and then use the MYSRCS variable as your file list in CMake commands (e.g., add_executable(my_app ${MYSRCS})). This would mean maintaining the "sources_list.txt" file externally but that would be easy to automate. I haven't actually tried this though so take all this with a pinch of salt.

      1 Reply Last reply
      1

      • Login

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