Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-29451

Investigate relative path handling for texture providers (or image providers in general)



    • Type: Suggestion
    • Status: Open
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.0.1
    • Fix Version/s: None
    • Labels:


      Regular image loading takes advantage of automatic resolution of paths. For example, if I have the following QML file:

      Image {
          source: "../images/myimage.png"

      the path to myimage.png will be resolved relative to MyFile.qml. This is quite useful, especially when using resource files.

      When using image providers, there is no automatic resolution. For example, if the source were changed to "image://myprovider/../images/myimage.png", myprovider would receive the path "../images/myimage.png", but no indication of how it should be resolved. This may not be an issue for many image providers, as they provide specialized loading, and aren't necessarily using a file path.

      However, particularly in the case of textures, texture providers are currently the preferred way to support a new format (rather than image format plugins), which means they cannot easily take advantage of automatic resolution relative to QML file.

      Possible alternatives:

      1. All paths are resolved by the texture provider, relative to the binary.
      2. A texture provider could have e.g. a setBaseUrl() function, which is used to resolve all paths.
      3. The following workaround could be used, though it becomes tedious if the entire application uses a texture provider:
        Image {
            property url resolvedSource: "../images/myimage.png"
            source: "image://myprovider/" + resolvedSource 
      4. The engine automatically resolves the last half of "image://myprovider/../images/myimage.png". This is problematic, as some providers may want to use relative paths, while others may want to use ids, which shouldn't be resolved as paths. Perhaps a special indication could be inserted to indicate the use of a path? e.g. always require a . or .. directly after "image://myprovider/", or provide a 'port', e.g.: "image://myprovider:relative/".

      I think (4) offers the nicest solution if it can be made to work.


          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              martinj Martin Jones
              mbrasser Michael Brasser
              0 Vote for this issue
              6 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes