The QUrlQuery class provides a way to manipulate a key-value pairs in a URL's query. 更多...
| 頭: | #include <QUrlQuery> |
| qmake: | QT += core |
| Since: | Qt 5.0 |
注意: 此類的所有函數 可重入 .
| QUrlQuery () | |
| QUrlQuery (const QUrl & url ) | |
| QUrlQuery (const QString & queryString ) | |
| QUrlQuery (const QUrlQuery & other ) | |
| ~QUrlQuery () | |
| void | addQueryItem (const QString & key , const QString & value ) |
| QStringList | allQueryItemValues (const QString & key , QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const |
| void | clear () |
| bool | hasQueryItem (const QString & key ) const |
| bool | isEmpty () const |
| QString | query (QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const |
| QString | queryItemValue (const QString & key , QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const |
| QList<QPair<QString, QString> > | queryItems (QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const |
| QChar | queryPairDelimiter () const |
| QChar | queryValueDelimiter () const |
| void | removeAllQueryItems (const QString & key ) |
| void | removeQueryItem (const QString & key ) |
| void | setQuery (const QString & queryString ) |
| void | setQueryDelimiters (QChar valueDelimiter , QChar pairDelimiter ) |
| void | setQueryItems (const QList<QPair<QString, QString> > & query ) |
| void | swap (QUrlQuery & other ) |
| QString | toString (QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const |
| bool | operator!= (const QUrlQuery & other ) const |
| QUrlQuery & | operator= (const QUrlQuery & other ) |
| QUrlQuery & | operator= (QUrlQuery && other ) |
| bool | operator== (const QUrlQuery & other ) const |
| QChar | defaultQueryPairDelimiter () |
| QChar | defaultQueryValueDelimiter () |
| uint | qHash (const QUrlQuery & key , uint seed = 0) |
The QUrlQuery class provides a way to manipulate a key-value pairs in a URL's query.
它被用來剖析在 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". QUrlQuery can also be used to create a query string suitable for use in QUrl::setQuery () 來自查詢的各個組件。
剖析查詢字符串的最常見方式是在構造函數中通過傳遞查詢字符串來初始化它。否則, setQuery () 方法可以用於設置要剖析的查詢。該方法還可以用於剖析帶有非標準定界符的查詢,需先設置它們使用 setQueryDelimiters () 函數。
可以再次獲取編碼查詢字符串,使用 query ()。這將獲取所有內部存儲項,並使用定界符編碼字符串。
All of the getter methods in QUrlQuery support an optional parameter of type QUrl::ComponentFormattingOptions ,包括 query (),規定如何編碼有問題數據。除瞭 QUrl::FullyDecoded ,返迴值仍必須被視為百分比編碼字符串,因為某些值無法以解碼形式錶達 (像:控製字符、不可解碼成 UTF-8 的字節序列)。齣於此原因,百分比字符始終由字符串 %25 錶示。
Web 瀏覽器通常將 HTML 錶單元素中的空格編碼成 + 加號,並將 + 加號編碼成 %2B 百分比編碼形式。不管怎樣,統治 URL 的互聯網規範並沒有將空格和 + 加號等價。
For that reason, QUrlQuery never 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, QUrlQuery also 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").
采用 QUrl::FullyDecoded 格式化,所有百分比編碼序列將被完全解碼,並使用 % 字符錶示自身。 QUrl::FullyDecoded 應小心使用,因為可能導緻數據丟失。見文檔編製 QUrl::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 QUrlQuery setters and query methods do not support the counterpart QUrl::DecodedMode 剖析,所以使用 QUrl::FullyDecoded 以獲取鍵列錶可能導緻在對象中找不到鍵。
默認情況下, QUrlQuery uses 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 that QUrlQuery uses for parsing and for reconstructing the query by calling setQueryDelimiters ().
非標準定界符應從被稱為子定界符的 RFC 3986 中選取。它們是:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
Use of other characters is not supported and may result in unexpected behaviour. QUrlQuery does not verify that you passed a valid delimiter.
另請參閱 QUrl .
構造空的 QUrlQuery object. A query can be set afterwards by calling setQuery () or items can be added by using addQueryItem ().
另請參閱 setQuery () 和 addQueryItem ().
構造 QUrlQuery object and parses the query string found in the url URL, using the default query delimiters. To parse a query string using other delimiters, you should first set them using setQueryDelimiters () and then set the query with setQuery ().
另請參閱 QUrl::query ().
構造 QUrlQuery object and parses the queryString query string, using the default query delimiters. To parse a query string using other delimiters, you should first set them using setQueryDelimiters () and then set the query with setQuery ().
拷貝內容從 other QUrlQuery 對象,包括查詢定界符。
銷毀此 QUrlQuery 對象。
追加對 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.
另請參閱 hasQueryItem () 和 queryItemValue ().
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.
另請參閱 queryItemValue () 和 addQueryItem ().
清零此 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.
另請參閱 isEmpty () 和 setQueryDelimiters ().
[static]
QChar
QUrlQuery::
defaultQueryPairDelimiter
()
Returns the default character for separating keys-value pairs from each other, an ampersand ("&").
另請參閱 setQueryDelimiters (), queryPairDelimiter (),和 defaultQueryValueDelimiter ().
[static]
QChar
QUrlQuery::
defaultQueryValueDelimiter
()
Returns the default character for separating keys from values in the query, an equal sign ("=").
另請參閱 setQueryDelimiters (), queryValueDelimiter (),和 defaultQueryPairDelimiter ().
返迴
true
if there is a query string pair whose key is equal to
key
from the URL.
另請參閱 addQueryItem () 和 queryItemValue ().
返迴
true
若此
QUrlQuery
object contains no key-value pairs, such as after being default-constructed or after parsing an empty query string.
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.
另請參閱 setQuery (), QUrl::setQuery (), QUrl::fragment (),和 編碼 .
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 ().
另請參閱 addQueryItem (), allQueryItemValues (),和 編碼 .
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 ().
另請參閱 setQueryItems () 和 編碼 .
Returns the character used to delimit between keys-value pairs when reconstructing the query string in query () or when parsing in setQuery ().
另請參閱 setQueryDelimiters () 和 queryValueDelimiter ().
Returns the character used to delimit between keys and values when reconstructing the query string in query () or when parsing in setQuery ().
另請參閱 setQueryDelimiters () 和 queryPairDelimiter ().
Removes all the query string pairs whose key is equal to key from the URL.
另請參閱 removeQueryItem ().
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 ().
另請參閱 removeAllQueryItems ().
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.
另請參閱 query ().
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)
注意: 非標準定界符應從被稱為子定界符的 RFC 3986 中選取。它們是:
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.
另請參閱 queryValueDelimiter () 和 queryPairDelimiter ().
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.
另請參閱 queryItems () 和 isEmpty ().
Swaps this URL query instance with other 。此函數非常快且從不失敗。
Returns this QUrlQuery 作為 QString . encoding can be used to specify the URL string encoding of the return value.
返迴
true
if
other
不等於此
QUrlQuery
。否則,返迴
false
.
另請參閱 operator== ().
拷貝內容從 other QUrlQuery 對象,包括查詢定界符。
移動賦值 other 到此 QUrlQuery 實例。
該函數在 Qt 5.2 引入。
返迴
true
if this object and the
other
object contain the same contents, in the same order, and use the same query delimiters.
返迴哈希值為 key ,使用 seed 做計算種子。
該函數在 Qt 5.6 引入。