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 Updated to NodeBB v4.3 + New Features

Qt5 Cmake project create qmldir

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 83 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 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 on 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

      • Login

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