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
。否则,
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
”.
URL 也可以逐段构造通过调用
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.
调用
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()
。使用
PySide.QtCore.QUrl.setQueryDelimiters()
to customize the delimiters used for generating the query string.
为方便生成编码 URL 字符串或查询字符串,有 2 个静态函数称为
PySide.QtCore.QUrl.fromPercentEncoding()
and
PySide.QtCore.QUrl.toPercentEncoding()
which deal with percent encoding and decoding of QStrings.
调用
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.
人类可读 URL 表示的抓取是采用
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
(URI 统一资源标识符:通用句法),而包括的方案扩展来自
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)).