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. [SOLVED] Use relative path of qml file A in qml file B
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Use relative path of qml file A in qml file B

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    DerMas
    wrote on last edited by
    #1

    I have the two qml files A and B. Both are in different directories.
    A is used in B and should display an image, which is located in the directory of B.
    But if I set the source of the image in A to "imageName.png" it doesn't work, since it uses the relative path of A and not of B.
    So how can I use the relative path of B in A?

    Here is an example:

    @
    /path/to/A.qml:
    Rectangle {
    property string imageSource
    Image { source: imageSource }
    }

    /other/Path/to/B.qml:
    Rectangle {
    A {
    imageSource: "image.png"
    }
    }

    Image is located at /other/Path/to/image.png (which is the path of B.qml)
    @

    The error message is like: Cannot find /path/to/image.png, which shows that the relative path of A.qml is used and not of B.qml

    So how can I use the relative path of B.qml in order to set the right path to the image for A.qml?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      I think you can use Qt."resolvedUrl(url url)":http://qt-project.org/doc/qt-4.8/qml-qt.html#resolvedUrl-method here which will give path of image.png relative to B.

      157

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerMas
        wrote on last edited by
        #3

        Works perfect, thanks :)

        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