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. How to import custom qml components via import <Module>.<Submodule> statements?>?
Forum Updated to NodeBB v4.3 + New Features

How to import custom qml components via import <Module>.<Submodule> statements?>?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 904 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.
  • K Offline
    K Offline
    Kamichanw
    wrote on last edited by
    #1

    I've written a custom qml UI library named KmcUI for instance. Here is directory strucuture.

    Myproject
     |- KmcUI
         |- Controls
              |- MyComponent.qml 
         |- qmldir
    |- main.qml
    

    And here is the content of qmldir

    module Kmc.Controls
    MyComponent 1.0 MyComponent.qml 
    

    I also set QML_IMPORT_PATH to $$PWD/KmcUI in .pro file.
    However, when I use import KmcUI.Controls in main.qml, it still shows QML module not found.

    K 1 Reply Last reply
    0
    • K Offline
      K Offline
      Kamichanw
      wrote on last edited by
      #3

      I finally found the solution!!! Everyone who is confused by Qt documentation should read my answer.

      You should do the following:

      1. Write qmldir for every sub directory, just like I described in question.
      2. Add all of the qmldirs and .qml files to a .qrc file that located in the outermost directory, in my case, is .\KmcUi. Don't forget to change the default prefix \ to the module name, in my case, is KmcUI.
      3. Create a .pri file, just include the .qrc just created in step 3. This step is optional, the most important is ensuring add .qrc in your .pro.
      4. In your own .pro file, include .pri or .qrc created in step 3 or step 2.
      5. Call engine.addImportPath("qrc:/"). You can also add following line to your .pro file. Then use INSTALL_PATH(engine).
      DEFINES += INSTALL_PATH\\(E\\)=\"E.addImportPath(QStringLiteral(\\\"qrc:/\\\"));\"
      
      1. Import your module in your own qml file!
      1 Reply Last reply
      0
      • K Kamichanw

        I've written a custom qml UI library named KmcUI for instance. Here is directory strucuture.

        Myproject
         |- KmcUI
             |- Controls
                  |- MyComponent.qml 
             |- qmldir
        |- main.qml
        

        And here is the content of qmldir

        module Kmc.Controls
        MyComponent 1.0 MyComponent.qml 
        

        I also set QML_IMPORT_PATH to $$PWD/KmcUI in .pro file.
        However, when I use import KmcUI.Controls in main.qml, it still shows QML module not found.

        K Offline
        K Offline
        Kamichanw
        wrote on last edited by
        #2

        I have posted the same quesiton here. Anyone can help?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kamichanw
          wrote on last edited by
          #3

          I finally found the solution!!! Everyone who is confused by Qt documentation should read my answer.

          You should do the following:

          1. Write qmldir for every sub directory, just like I described in question.
          2. Add all of the qmldirs and .qml files to a .qrc file that located in the outermost directory, in my case, is .\KmcUi. Don't forget to change the default prefix \ to the module name, in my case, is KmcUI.
          3. Create a .pri file, just include the .qrc just created in step 3. This step is optional, the most important is ensuring add .qrc in your .pro.
          4. In your own .pro file, include .pri or .qrc created in step 3 or step 2.
          5. Call engine.addImportPath("qrc:/"). You can also add following line to your .pro file. Then use INSTALL_PATH(engine).
          DEFINES += INSTALL_PATH\\(E\\)=\"E.addImportPath(QStringLiteral(\\\"qrc:/\\\"));\"
          
          1. Import your module in your own qml file!
          1 Reply Last reply
          0
          • K Kamichanw has marked this topic as solved on

          • Login

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