[Qt-qml] Relative to absolute paths, and z-order comparison
warwick.allison at nokia.com
warwick.allison at nokia.com
Tue Mar 30 08:37:43 CEST 2010
> 1) Is there a way to turn a relative path/URL into an absolute one?
Michael mentions Qt.resolvedUrl, but you should also be aware of the automatic resolving of strings to urls.
If a property is of type url, it is automatically converted to be absolute by resolving against the caller. So, for example, given these files:
/bar/subdir/foo.html
/bar/content/UrlDisplay.qml
/bar/Bar.qml
Where UrlDisplay.qml is:
import Qt 4.6
Text {
property url displayurl
text: displayurl
}
and Bar.qml is:
import "content"
UrlDisplay {
displayurl: "subdir/foo.html"
}
Then the text that is displayed will be:
file:///bar/subdir/foo.html
The important thing here is that the setting of the displayurl property (of type "url") to "subdir/foo.html" is converted in the context where it is assigned - in Bar.qml, or rather file:///bar/Bar.qml, and is thus resolved relative to that.
In contrast, if you just used strings for the property, the object (UrlDisplay) would not be able to usefully resolve it, since it would not have a useful context - it would not, for example, be correct to resolve "subdir/foo.html" in UrlDisplay.qml - since that would be file:///bar/content/subdir/foo.html
--
Warwick
More information about the Qt-qml
mailing list