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. Loading resources in a file embedded in a resource file
Forum Updated to NodeBB v4.3 + New Features

Loading resources in a file embedded in a resource file

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.8k 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.
  • Z Offline
    Z Offline
    Zanis
    wrote on last edited by
    #1

    My problem sounded like this : http://qt-project.org/forums/viewthread/10477 but, bad luck, it's not.

    My problem starts the same way : I put my qml files into resource file (qmlfiles.qrc) and I want to access images into these qml files. But the fact is that my images are in another resource file (image.qrc)

    So for example I'm trying to do this :

    @Item{
    source: "qrc:/sprites/myImage.png"
    }@

    and the qrc looks like this :

    @<RCC>
    <qresource prefix="/sprites">
    <file alias="myImage">images/myImage.png</file>
    </qresource>
    </RCC>@

    But in the log, there is QML Image: Cannot open: qrc:/sprites/myImage.png. Is it because he's trying to access a file in a resource file that is not the same where the qml file is ? Any idea for that problem ?

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

      Having 2 separate resource files should not be a problem, the system is completely transparent and can work with multiple QRC files (even sharing the same prefix!).

      (Z(:^

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zanis
        wrote on last edited by
        #3

        Yeah that's why it sounds weird to me. I never had such problem with qrc files on my other Qt (but without qml) applications.

        The way of loading a qrc item is "qrc:/prefix/myFile", right ? If I don't make a mistake, then I don't see how that cannot work...

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

          Yes, it's either ":/prefix/file" or "qrc:/prefix/file" (both should work the same, but rarely do). You can try passing the path without any reference to QRC, though. Since you are loading QML from the resource file, the engine already assumes all the paths are QRC-based, too. So you can try with simply:
          @
          Image {
          source: "sprites/myImage.png"
          }
          @

          (Z(:^

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zanis
            wrote on last edited by
            #5

            I've solved the problem by putting some alias and regrouping the qml and image files into the same .qrc file but organized with different prefixes.

            But now I've got another problem. I've put all my qml files into the same qrc file and I'm trying to initiate a pathview with a ListModel. The List Model is in a file alone and the PathView in another qml file.

            I'm trying to do :

            @PathView {
            id: myPathView
            delegate: myDelegate
            model: myModel
            [...]
            }@

            with my ListModel looking like this :

            @import QtQuick 2.0

            ListModel {
            id: myModel
            ListElement {
            name: "MyElement1"
            }
            ListElement {
            name: "MyElement2"
            }
            ListElement {
            name: "MyElement3"
            }
            }@

            But the pathview doesn't find the ListModel. When I tried something similar with a test projet and qml files that weren't in a .qrc file, it worked without any problem. It seems that when .qrc are involved, scopes are different... Any ideas ?

            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