Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to put a QML component into a QML module? (CMake)
Qt 6.12 LTS is out! See what's new in the release blog

How to put a QML component into a QML module? (CMake)

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 423 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.
  • P Offline
    P Offline
    paulmasri
    wrote on last edited by
    #1

    How can I take a QML component (.qml file) and put it in a separate QML module, in CMake?

    At the moment I'm including all QML components in the main app module and that works fine. But when I try to move some of them into separate modules (and add the import statement in main.qml of course), I get the runtime error "MyImportedComponent is not a type".

    NB: In Qt Creator, in main.qml, the import statement is parsed fine and MyImportedComponent shows up correctly colour-coded (not M300 error).

    Here's what I tried...

    All in the app module works fine:

    qt_add_qml_module(appMyProject URI MyProject VERSION 1.0
      QML_FILES
        main.qml
        MyImportedComponent.qml
    )
    target_link_libraries(appMyProject PRIVATE Qt6::Quick)
    

    Separate module doesn't:

    qt_add_qml_module(SeparateModule URI SeparateModule VERSION 1.0
      OUTPUT_DIRECTORY SeparateModule
      QML_FILES
        MyImportedComponent.qml
    )
    qt_add_qml_module(appMyProject URI MyProject VERSION 1.0
      QML_FILES
        main.qml
    )
    target_link_libraries(appMyProject PRIVATE Qt6::Quick SeparateModule)
    
    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
    • Unsolved