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

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

    XMLWordPrintable

Details

    Description

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

      MyFile.qml
      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.

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes