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. Qt5 Cmake project create qmldir
Forum Update on Monday, May 27th 2025

Qt5 Cmake project create qmldir

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 66 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.
  • E Offline
    E Offline
    Edanaz
    wrote on 25 Apr 2025, 12:46 last edited by
    #1

    Hello, I am using qt5 in my project and I have made a cmake configuration. I keep more than one qml file in qrc in the project and I want to be able to call and import them as a module. For this, I use qmldir, but the module cannot be imported. Can you help me with this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Shrishashank
      wrote 27 days ago last edited by
      #2

      The QML files and the qmldir file must be placed inside a module folder, e.g., qml/MyModule/.

      The qmldir file must be added to the .qrc resource file along with all the QML files it references.

      The qmldir file must include:

      A module declaration: module MyModule

      A list of all QML types with version and filename:
      Example: MyItem 1.0 MyItem.qml

      In C++, you must call

      engine.addImportPath("qrc:/qml");
      

      This tells the QML engine to look for modules inside the .qrc resource system.

      In your qml.qrc, you must include all files in the correct relative path:

      <file>qml/MyModule/qmldir</file>
      <file>qml/MyModule/MyItem.qml</file>
      
      

      Use the module in QML with the correct name and version, as defined in qmldir:

      import MyModule 1.0
      
      

      Filenames in qmldir must match exactly (case-sensitive) with the actual file names.

      CMake must include the .qrc file using qt5_add_resources() and link against Qt5::Qml and Qt5::Quick.

      SHRISHASHANK S K

      1 Reply Last reply
      0

      1/2

      25 Apr 2025, 12:46

      • Login

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