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. QML and Qt Quick
  4. QML resource management in 5.9
Qt 6.12 LTS is out! See what's new in the release blog

QML resource management in 5.9

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 946 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
    pholz
    wrote on last edited by pholz
    #1

    I am migrating my project from Qt 5.5 to Qt 5.9.

    the project is organized as follows:

    * proj root
      * data
        * quick
          * uiMain.qml
          * otherComponent.qml
          * ...
      * prj
        * myApp
          * project
            * myApp.pro
    

    The major problem is the following: I used to run the application in working dir proj root and load my qml source like this:

    myQQuickViewInstance->setSource(QUrl::fromLocalFile("data/quick/uiMain.qml"));
    

    uiMain used to get loaded and could simply use otherComponent and all other qml types in the same subdirectory.

    As of Qt 5.9, the call to setSource() triggers an assertion fail because relative file paths are not allowed anymore. I have tried to migrate everything to Resources and now I'm loading the main QML file like this:

    myQQuickViewInstance->setSource(QUrl("qrc:/myPrefix/ui.qml"))
    

    and in the qrc file:

    <qresource lang="qml" prefix="/myPrefix">
        <file alias="ui.qml">../../../data/quick/uiMain.qml</file>
        <file alias="otherComponent.qml">../../../data/quick/otherComponent.qml</file>
        // etc...
    

    The main file now loads correctly, but QML files (types) in the same subdir are not recognized anymore.
    I tried this:

     import "qrc:myPrefix/otherComponent.qml" as OtherComponent
    

    But I get errors such as OtherComponent cannot be used as a type. Also, this type of import isn't documented anywhere. All the docs say that other QML files in the same subdir should be recognized automatically.

    What is the correct way to handle this? Preferably without adding dozens of import statements all over my 20 QML files.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You don't need the import statement at all, the OtherComponent file is already in the same directory (it's name should start with a capital letter, though!).

      And if you really want to use the QRC notation, it should look like this:

      import "qrc:/myPrefix/otherComponent.qml" as OtherComponent
      

      (Z(:^

      1 Reply Last reply
      1

      • Login

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