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

Unable to create QML custom modules in cmake

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmlqml modules
3 Posts 2 Posters 391 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 4 Mar 2023, 12:21 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 4 Mar 2023, 12:27
    0
    • A akshaybabloo
      4 Mar 2023, 12:21

      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 4 Mar 2023, 12:27 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 5 Mar 2023, 00:01
      0
      • ? A Former User
        4 Mar 2023, 12:27

        @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 5 Mar 2023, 00:01 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        4 Mar 2023, 12:21

        • Login

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