The PySide.QtCore.QUrl class provides a convenient interface for working with URLs.
It can parse and construct URLs in both encoded and unencoded form. PySide.QtCore.QUrl also has support for internationalized domain names (IDNs).
The most common way to use PySide.QtCore.QUrl is to initialize it via the constructor by passing a PySide.QtCore.QString . Otherwise, PySide.QtCore.QUrl.setUrl() and PySide.QtCore.QUrl.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 PySide.QtCore.QUrl.setScheme() , PySide.QtCore.QUrl.setUserName() , PySide.QtCore.QUrl.setPassword() , PySide.QtCore.QUrl.setHost() , PySide.QtCore.QUrl.setPort() , PySide.QtCore.QUrl.setPath() , PySide.QtCore.QUrl.setEncodedQuery() and PySide.QtCore.QUrl.setFragment() . Some convenience functions are also available: PySide.QtCore.QUrl.setAuthority() sets the user name, password, host and port. PySide.QtCore.QUrl.setUserInfo() sets the user name and password at once.
Call PySide.QtCore.QUrl.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 PySide.QtCore.QUrl.setQueryItems() , PySide.QtCore.QUrl.addQueryItem() and PySide.QtCore.QUrl.removeQueryItem() . Use PySide.QtCore.QUrl.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 PySide.QtCore.QUrl.fromPercentEncoding() and PySide.QtCore.QUrl.toPercentEncoding() which deal with percent encoding and decoding of QStrings.
Calling PySide.QtCore.QUrl.isRelative() will tell whether or not the URL is relative. A relative URL can be resolved by passing it as argument to PySide.QtCore.QUrl.resolved() , which returns an absolute URL. PySide.QtCore.QUrl.isParentOf() is used for determining whether one URL is a parent of another.
PySide.QtCore.QUrl.fromLocalFile() constructs a PySide.QtCore.QUrl by parsing a local file path. PySide.QtCore.QUrl.toLocalFile() converts a URL to a local file path.
The human readable representation of the URL is fetched with PySide.QtCore.QUrl.toString() . This representation is appropriate for displaying a URL to a user in unencoded form. The encoded form however, as returned by PySide.QtCore.QUrl.toEncoded() , is for internal use, passing to web servers, mail clients and so on.
PySide.QtCore.QUrl conforms to the URI specification from RFC 3986 (Uniform Resource Identifier: Generic Syntax), and includes scheme extensions from RFC 1738 (Uniform Resource Locators). Case folding rules in PySide.QtCore.QUrl conform to RFC 3491 (Nameprep: A Stringprep Profile for Internationalized Domain Names (IDN)).