Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to create QML custom modules in cmake
Forum Update on Monday, May 27th 2025

Unable to create QML custom modules in cmake

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmlqml modules
3 Posts 2 Posters 378 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.
  • A Offline
    A Offline
    akshaybabloo
    wrote on last edited by
    #1

    I am trying to create a custom QML module in cmake and I keep getting

    QQmlApplicationEngine failed to load component
    qrc:/QmlModules/main.qml:2:1: module "CustomItem" is not installed
    

    I have create a file called CustomPopup.qml in $CWD/qml/CustomItem/, in the same CustomItem folder, I have a qmldir file with the following content:

    module CustomItem
    CustomPopup 1.0 ./CustomPopup.qml
    

    And in CMakeLists.txt I added:

    list(APPEND QML_DIRS "${CMAKE_SOURCE_DIR}/qml")
    set(QML_IMPORT_PATH ${QML_DIRS} CACHE STRING "Custom modules" FORCE)
    

    Also, in main.cpp, I added:

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

    I still get the same error. Not sure what am I missing. Any help here would be appreciated.

    Repository of this example is at https://github.com/akshaybabloo/QmlModules

    ? 1 Reply Last reply
    0
    • A akshaybabloo

      I am trying to create a custom QML module in cmake and I keep getting

      QQmlApplicationEngine failed to load component
      qrc:/QmlModules/main.qml:2:1: module "CustomItem" is not installed
      

      I have create a file called CustomPopup.qml in $CWD/qml/CustomItem/, in the same CustomItem folder, I have a qmldir file with the following content:

      module CustomItem
      CustomPopup 1.0 ./CustomPopup.qml
      

      And in CMakeLists.txt I added:

      list(APPEND QML_DIRS "${CMAKE_SOURCE_DIR}/qml")
      set(QML_IMPORT_PATH ${QML_DIRS} CACHE STRING "Custom modules" FORCE)
      

      Also, in main.cpp, I added:

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

      I still get the same error. Not sure what am I missing. Any help here would be appreciated.

      Repository of this example is at https://github.com/akshaybabloo/QmlModules

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @akshaybabloo Hi

      I've noticed that running CMake doesn't refresh some stuff like pathes. In that case I advice you go to projects, in CMake category select Initial Configuration tab, and re-configure with initial parameters.

      For the engine->addImportPath, don't specify a qrc:/ path if you didn't set a resource file, just specify the path to the main QML file without the :/ that is for qrc path.

      A 1 Reply Last reply
      0
      • ? A Former User

        @akshaybabloo Hi

        I've noticed that running CMake doesn't refresh some stuff like pathes. In that case I advice you go to projects, in CMake category select Initial Configuration tab, and re-configure with initial parameters.

        For the engine->addImportPath, don't specify a qrc:/ path if you didn't set a resource file, just specify the path to the main QML file without the :/ that is for qrc path.

        A Offline
        A Offline
        akshaybabloo
        wrote on last edited by
        #3

        @ankou29666 That did not work too. Also, I do have a qrc path

        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