Priority: P3: Somewhat important
Affects Version/s: 5.0.1
Fix Version/s: None
Regular image loading takes advantage of automatic resolution of paths. For example, if I have the following QML file:
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.
- All paths are resolved by the texture provider, relative to the binary.
- A texture provider could have e.g. a setBaseUrl() function, which is used to resolve all paths.
- The following workaround could be used, though it becomes tedious if the entire application uses a texture provider:
- 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.