- Qt 6.8
- Qt Qml
- QML Types
- url
- Qt 6.8.1 Reference Documentation

# url QML Value Type

a resource locator. More...

## Detailed Description

The `url` type refers to a resource locator (like a file name, for example). It can be either absolute, e.g. "http://qt-project.org", or relative, e.g. "pics/logo.png". A relative URL is resolved relative to the URL of the containing component.

For example, the following assigns a valid URL to the Image::source property, which is of type `url`:

     Image { source: "pics/logo.png" }

When integrating with C++, note that any QUrl value passed into QML from C++ is automatically converted into a `url` value, and vice-versa.

Alternatively you may convert your `url` to a URL object in order to access and modify its components:

     var urlObject = new URL(url);

Note: In Qt 5, URLs were automatically resolved based on the current context when assigning them to any `url` property. This made it impossible to work with relative URLs and it created inconsistent behavior when reading back a URL previously written to a property. Therefore, the behavior was changed in Qt 6: URLs are not automatically resolved on assignment anymore. The individual elements that use URLs have to resolve them themselves.

Note: When referring to files stored with the Qt Resource System from within QML, you should use "qrc:///" instead of ":/" as QML requires URL paths. Relative URLs resolved from within that file will use the same protocol.

Additionally, URLs may contain encoded characters using the 'percent-encoding' scheme specified by RFC 3986. These characters will be preserved within properties of type `url`, to allow QML code to construct precise URL values.

For example, a local file containing a '#' character, which would normally be interpreted as the beginning of the URL 'fragment' element, can be accessed by encoding the characters of the file name:

     Image { source: encodeURIComponent("/tmp/test#1.png") }

This value type is provided by the QML language.

See also QML Value Types.