![]() |
Home · Overviews · Examples | ![]() |
The QUrl class provides a convenient interface for working with URLs. More...
The QUrl class provides a convenient interface for working with URLs.
It can parse and construct URLs in both encoded and unencoded form. QUrl also has support for internationalized domain names (IDNs).
The most common way to use QUrl is to initialize it via the constructor by passing a QString. Otherwise, setUrl and setEncodedUrl can also be used.
URLs can be represented in two forms: encoded or unencoded. The unencoded representation is suitable for showing to users, but the encoded representation is typically what you would send to a web server. For example, the unencoded URL "http://bühler.example.com" would be sent to the server as "http://xn--bhler-kva.example.com/List%20of%20applicants.xml".
A URL can also be constructed piece by piece by calling setScheme, setUserName, setPassword, setHost, setPort, setPath, setEncodedQuery and setFragment. Some convenience functions are also available: setAuthority sets the user name, password, host and port. setUserInfo sets the user name and password at once.
Call isValid to check if the URL is valid. This can be done at any point during the constructing of a URL.
Constructing a query is particularly convenient through the use of setQueryItems, addQueryItem and removeQueryItem. Use setQueryDelimiters to customize the delimiters used for generating the query string.
For the convenience of generating encoded URL strings or query strings, there are two static functions called fromPercentEncoding and toPercentEncoding which deal with percent encoding and decoding of QStrings.
Calling isRelative will tell whether or not the URL is relative. A relative URL can be resolved by passing it as argument to resolved, which returns an absolute URL. isParentOf is used for determining whether one URL is a parent of another.
fromLocalFile constructs a QUrl by parsing a local file path. toLocalFile converts a URL to a local file path.
The human readable representation of the URL is fetched with toString. This representation is appropriate for displaying a URL to a user in unencoded form. The encoded form however, as returned by toEncoded, is for internal use, passing to web servers, mail clients and so on.
QUrl conforms to the URI specification from RFC 3986 (Uniform Resource Identifier: Generic Syntax), and includes scheme extensions from RFC 1738 (Uniform Resource Locators).
See also QUrlInfo.
Copyright © 2008 Trolltech | Trademarks | Qt Jambi 4.3.4_01 |