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. qt_add_qml_module and project structure
Forum Updated to NodeBB v4.3 + New Features

qt_add_qml_module and project structure

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 702 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.
  • M Offline
    M Offline
    morte
    wrote on last edited by morte
    #1

    main.qml located at project_root/qml/main.qml (${CMAKE_CURRENT_SOURCE_DIR}/qml/main.qml)

    CMakeLists.txt:

    ...
    qt_add_executable(untitled main.cpp )
    
    qt_add_qml_module(untitled
        URI qml
        VERSION 1.0
        QML_FILES
          qml/main.qml
    )
    ...
    

    main.cpp:

    engine.load(QUrl("qrc:/qml/main.qml"));
    

    Application output:

    qrc:/qml/main.qml: No such file or directory
    

    Qt version is 6.4.2/6.4.3. Why main.qml is unaccessible while it should be available at "qrc:/${URI}/main.qml"?

    ? 1 Reply Last reply
    0
    • M morte

      main.qml located at project_root/qml/main.qml (${CMAKE_CURRENT_SOURCE_DIR}/qml/main.qml)

      CMakeLists.txt:

      ...
      qt_add_executable(untitled main.cpp )
      
      qt_add_qml_module(untitled
          URI qml
          VERSION 1.0
          QML_FILES
            qml/main.qml
      )
      ...
      

      main.cpp:

      engine.load(QUrl("qrc:/qml/main.qml"));
      

      Application output:

      qrc:/qml/main.qml: No such file or directory
      

      Qt version is 6.4.2/6.4.3. Why main.qml is unaccessible while it should be available at "qrc:/${URI}/main.qml"?

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

      @morte hi

      you have to declare your "qrc:/" resources into a specific file.
      This is described here

      and you have to declare this .qrc file into your CmakeLists.txt, not forgetting to set CMAKE_AUTORCC on, which isn't done by default in QtQuick.

      set(CMAKE_AUTORCC ON)
      
      qt_add_executable(my_app
          application.qrc
          main.cpp
      )
      
      M 1 Reply Last reply
      0
      • ? A Former User

        @morte hi

        you have to declare your "qrc:/" resources into a specific file.
        This is described here

        and you have to declare this .qrc file into your CmakeLists.txt, not forgetting to set CMAKE_AUTORCC on, which isn't done by default in QtQuick.

        set(CMAKE_AUTORCC ON)
        
        qt_add_executable(my_app
            application.qrc
            main.cpp
        )
        
        M Offline
        M Offline
        morte
        wrote on last edited by
        #3

        @ankou29666 no, in case of Qt 6.2+ with qt_add_qml_module() thats not the right way to add qml files as qt_add_qml_module() registers them in resource system

        ? 1 Reply Last reply
        0
        • M morte

          @ankou29666 no, in case of Qt 6.2+ with qt_add_qml_module() thats not the right way to add qml files as qt_add_qml_module() registers them in resource system

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

          @morte oops yes sorry I didn't pay attention that you used that syntax inside your CMakeLists.txt (I use the qrc files instead thus the confusion).

          but what about autorcc ?

          1st edit : I am unsure but I would try adding the prefix /

          qt_add_qml_module(untitled
              URI qml
              VERSION 1.0
              PREFIX "/"
              QML_FILES
                qml/main.qml
          )
          

          2nd edit : in fact no, I'm confusing qt_add_qml_module with qt_add_resources, so that might be RESOURCE_PREFIX instead of PREFIX ?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            morte
            wrote on last edited by
            #5

            I figured out that its accessible by "qrc:/qml/qml/main.qml" e.g. URI plus path to qml file relative to project root. URI can be stripped out by declaring NO_RESOURCE_TARGET_PATH.

            1 Reply Last reply
            0
            • M morte has marked this topic as solved on
            • M morte has marked this topic as unsolved on
            • M Offline
              M Offline
              morte
              wrote on last edited by
              #6

              However i still dont understand is there relation between URI and project directory tree. Why they write in documentation "The easiest way to structure QML modules is to keep them in directories named by their URIs." as i can set URI to "my.new.module" while on project tree files can be located at "project_root/whatever/" e.g. whats point to mimic URI in directory tree

              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