New in version 5.0.
def
__eq__
(other)
def
__ne__
(other)
def
addQueryItem
(key, value)
def
allQueryItemValues
(key[, encoding=QUrl.PrettyDecoded])
def
clear
()
def
hasQueryItem
(key)
def
isEmpty
()
def
query
([encoding=QUrl.PrettyDecoded])
def
queryItemValue
(key[, encoding=QUrl.PrettyDecoded])
def
queryItems
([encoding=QUrl.PrettyDecoded])
def
queryPairDelimiter
()
def
queryValueDelimiter
()
def
removeAllQueryItems
(key)
def
removeQueryItem
(key)
def
setQuery
(queryString)
def
setQueryDelimiters
(valueDelimiter, pairDelimiter)
def
setQueryItems
(query)
def
swap
(other)
def
toString
([encoding=QUrl.PrettyDecoded])
def
defaultQueryPairDelimiter
()
def
defaultQueryValueDelimiter
()
它被用来剖析在 URL 中找到的查询字符串,像以下:
![]()
Query strings like the above are used to transmit options in the URL and are usually decoded into multiple key-value pairs. The one above would contain two entries in its list, with keys “type” and “color”.
QUrlQuerycan also be used to create a query string suitable for use insetQuery()from the individual components of the query.剖析查询字符串的最常见方式是在构造函数中通过传递查询字符串来初始化它。否则,
setQuery()method can be used to set the query to be parsed. That method can also be used to parse a query with non-standard delimiters, after having set them using thesetQueryDelimiters()函数。可以再次获取编码查询字符串,使用
query(). This will take all the internally-stored items and encode the string using the delimiters.
All of the getter methods in
QUrlQuerysupport an optional parameter of typeComponentFormattingOptions,包括query(), which dictate how to encode the data in question. Except forFullyDecoded, the returned value must still be considered a percent-encoded string, as there are certain values which cannot be expressed in decoded form (like control characters, byte sequences not decodable to UTF-8). For that reason, the percent character is always represented by the string “%25”.
Web browsers usually encode spaces found in HTML FORM elements to a plus sign (“+”) and plus signs to its percent-encoded form (%2B). However, the Internet specifications governing URLs do not consider spaces and the plus character equivalent.
For that reason,
QUrlQuerynever encodes the space character to “+” and will never decode “+” to a space character. Instead, space characters will be rendered “%20” in encoded form.To support encoding like that of HTML forms,
QUrlQueryalso never decodes the “%2B” sequence to a plus sign nor encode a plus sign. In fact, any “%2B” or “+” sequences found in the keys, values, or query string are left exactly like written (except for the uppercasing of “%2b” to “%2B”).
With
FullyDecodedformatting, all percent-encoded sequences will be decoded fully and the ‘%’ character is used to represent itself.FullyDecoded应小心使用,因为可能导致数据丢失。见文档编制FullyDecoded了解可能丢失什么数据的有关信息。This formatting mode should be used only when dealing with text presented to the user in contexts where percent-encoding is not desired. Note that
QUrlQuerysetters and query methods do not support the counterpartDecodedMode剖析,因此使用FullyDecoded以获取键列表可能导致在对象中找不到键。
默认情况下,
QUrlQueryuses an equal sign (“=”) to separate a key from its value, and an ampersand (“&”) to separate key-value pairs from each other. It is possible to change the delimiters thatQUrlQueryuses for parsing and for reconstructing the query by callingsetQueryDelimiters().Non-standard delimiters should be chosen from among what RFC 3986 calls “sub-delimiters”. They are:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="Use of other characters is not supported and may result in unexpected behaviour.
QUrlQuerydoes not verify that you passed a valid delimiter.另请参阅
QUrlQuery
¶
构造空
QUrlQuery
object. A query can be set afterwards by calling
setQuery()
or items can be added by using
addQueryItem()
.
另请参阅
PySide2.QtCore.QUrlQuery.
addQueryItem
(
key
,
value
)
¶
key – unicode
value – unicode
追加对
key
=
value
to the end of the query string of the URL. This method does not overwrite existing items that might exist with the same key.
注意
This method does not treat spaces (ASCII 0x20) and plus (“+”) signs as the same, like HTML forms do. If you need spaces to be represented as plus signs, use actual plus signs.
PySide2.QtCore.QUrlQuery.
allQueryItemValues
(
key
[
,
encoding=QUrl.PrettyDecoded
]
)
¶
key – unicode
encoding
–
ComponentFormattingOptions
字符串列表
Returns the a list of query string values whose key is equal to
key
from the URL, using the options specified in
encoding
to encode the return value. If the key
key
is not found, this function returns an empty list.
PySide2.QtCore.QUrlQuery.
clear
(
)
¶
清零此
QUrlQuery
object by removing all of the key-value pairs currently stored. If the query delimiters have been changed, this function will leave them with their changed values.
PySide2.QtCore.QUrlQuery.
defaultQueryPairDelimiter
(
)
¶
QChar
Returns the default character for separating keys-value pairs from each other, an ampersand (“&”).
PySide2.QtCore.QUrlQuery.
defaultQueryValueDelimiter
(
)
¶
QChar
Returns the default character for separating keys from values in the query, an equal sign (“=”).
PySide2.QtCore.QUrlQuery.
hasQueryItem
(
key
)
¶
key – unicode
bool
返回
true
if there is a query string pair whose key is equal to
key
from the URL.
PySide2.QtCore.QUrlQuery.
isEmpty
(
)
¶
bool
返回
true
若此
QUrlQuery
object contains no key-value pairs, such as after being default-constructed or after parsing an empty query string.
另请参阅
PySide2.QtCore.QUrlQuery.
__ne__
(
other
)
¶
other
–
QUrlQuery
bool
返回
true
if
other
不等于此
QUrlQuery
。否则,返回
false
.
另请参阅
operator==()
PySide2.QtCore.QUrlQuery.
__eq__
(
other
)
¶
other
–
QUrlQuery
bool
返回
true
if this object and the
other
object contain the same contents, in the same order, and use the same query delimiters.
PySide2.QtCore.QUrlQuery.
query
(
[
encoding=QUrl.PrettyDecoded
]
)
¶
encoding
–
ComponentFormattingOptions
unicode
Returns the reconstructed query string, formed from the key-value pairs currently stored in this
QUrlQuery
object and separated by the query delimiters chosen for this object. The keys and values are encoded using the options given by the
encoding
参数。
For this function, the only ambiguous delimiter is the hash (“#”), as in URLs it is used to separate the query string from the fragment that may follow.
The order of the key-value pairs in the returned string is exactly the same as in the original query.
另请参阅
PySide2.QtCore.QUrlQuery.
queryItemValue
(
key
[
,
encoding=QUrl.PrettyDecoded
]
)
¶
key – unicode
encoding
–
ComponentFormattingOptions
unicode
Returns the query value associated with key
key
from the URL, using the options specified in
encoding
to encode the return value. If the key
key
is not found, this function returns an empty string. If you need to distinguish between an empty value and a non-existent key, you should check for the key’s presence first using
hasQueryItem()
.
If the key
key
is multiply defined, this function will return the first one found, in the order they were present in the query string or added using
addQueryItem()
.
另请参阅
PySide2.QtCore.QUrlQuery.
queryItems
(
[
encoding=QUrl.PrettyDecoded
]
)
¶
encoding
–
ComponentFormattingOptions
Returns the query string of the URL, as a map of keys and values, using the options specified in
encoding
to encode the items. The order of the elements is the same as the one found in the query string or set with
setQueryItems()
.
另请参阅
PySide2.QtCore.QUrlQuery.
queryPairDelimiter
(
)
¶
QChar
Returns the character used to delimit between keys-value pairs when reconstructing the query string in
query()
or when parsing in
setQuery()
.
PySide2.QtCore.QUrlQuery.
queryValueDelimiter
(
)
¶
QChar
Returns the character used to delimit between keys and values when reconstructing the query string in
query()
or when parsing in
setQuery()
.
PySide2.QtCore.QUrlQuery.
removeAllQueryItems
(
key
)
¶
key – unicode
Removes all the query string pairs whose key is equal to
key
from the URL.
另请参阅
PySide2.QtCore.QUrlQuery.
removeQueryItem
(
key
)
¶
key – unicode
Removes the query string pair whose key is equal to
key
from the URL. If there are multiple items with a key equal to
key
, it removes the first item in the order they were present in the query string or added with
addQueryItem()
.
PySide2.QtCore.QUrlQuery.
setQuery
(
queryString
)
¶
queryString – unicode
Parses the query string in
queryString
and sets the internal items to the values found there. If any delimiters have been specified with
setQueryDelimiters()
, this function will use them instead of the default delimiters to parse the string.
另请参阅
PySide2.QtCore.QUrlQuery.
setQueryDelimiters
(
valueDelimiter
,
pairDelimiter
)
¶
valueDelimiter
–
QChar
pairDelimiter
–
QChar
Sets the characters used for delimiting between keys and values, and between key-value pairs in the URL’s query string. The default value delimiter is ‘=’ and the default pair delimiter is ‘&’.
valueDelimiter
will be used for separating keys from values, and
pairDelimiter
will be used to separate key-value pairs. Any occurrences of these delimiting characters in the encoded representation of the keys and values of the query string are percent encoded when returned in
query()
.
若
valueDelimiter
is set to ‘(‘ and
pairDelimiter
is ‘)’, the above query string would instead be represented like this:
http://www.example.com/cgi-bin/drawgraph.cgi?type-pie/color-green
注意
Non-standard delimiters should be chosen from among what RFC 3986 calls “sub-delimiters”. They are:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
Use of other characters is not supported and may result in unexpected behaviour. This method does not verify that you passed a valid delimiter.
PySide2.QtCore.QUrlQuery.
setQueryItems
(
query
)
¶
query –
Sets the items in this
QUrlQuery
对象到
query
. The order of the elements in
query
is preserved.
注意
This method does not treat spaces (ASCII 0x20) and plus (“+”) signs as the same, like HTML forms do. If you need spaces to be represented as plus signs, use actual plus signs.
另请参阅