QUrlQuery 類提供操縱 URL 查詢中鍵/值對的方式。 更多...
| 頭: | #include <QUrlQuery> |
| qmake: | QT += core |
| Since: | Qt 5.0 |
該類在 Qt 5.0 引入。
注意: 此類的所有函數 可重入 .
| QUrlQuery (const QUrlQuery & other ) | |
| QUrlQuery (std::initializer_list<QPair<QString, QString>> list ) | |
| QUrlQuery (const QString & queryString ) | |
| QUrlQuery (const QUrl & url ) | |
| QUrlQuery () | |
| QUrlQuery & | operator= (QUrlQuery && other ) |
| QUrlQuery & | operator= (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 |
| bool | operator== (const QUrlQuery & other ) const |
| QChar | defaultQueryPairDelimiter () |
| QChar | defaultQueryValueDelimiter () |
| uint | qHash (const QUrlQuery & key , uint seed = 0) |
它被用來剖析在 URL 中找到的查詢字符串,像以下:
像上麵的查詢字符串用於傳輸 URL 選項,且通常被解碼成多個鍵-值對。以上在其列錶中包含 2 個條目,采用鍵 type 和 color。QUrlQuery 也可以用來創建查詢字符串,適閤用於 QUrl::setQuery () 來自查詢的各個組件。
剖析查詢字符串的最常見方式是在構造函數中通過傳遞查詢字符串來初始化它。否則, setQuery () 方法可以用於設置要剖析的查詢。該方法還可以用於剖析帶有非標準定界符的查詢,需先設置它們使用 setQueryDelimiters () 函數。
可以再次獲取編碼查詢字符串,使用 query ()。這將獲取所有內部存儲項,並使用定界符編碼字符串。
QUrlQuery 中的所有 Getter 方法支持可選參數類型 QUrl::ComponentFormattingOptions ,包括 query (),規定如何編碼有問題數據。除瞭 QUrl::FullyDecoded ,返迴值仍必須被視為百分比編碼字符串,因為某些值無法以解碼形式錶達 (像:控製字符、不可解碼成 UTF-8 的字節序列)。齣於此原因,百分比字符始終由字符串 %25 錶示。
Web 瀏覽器通常將 HTML 錶單元素中的空格編碼成 + 加號,並將 + 加號編碼成 %2B 百分比編碼形式。不管怎樣,統治 URL 的互聯網規範並沒有將空格和 + 加號等價。
齣於此原因,QUrlQuery 從不將空格字符編碼成 +,也從不將 + 解碼成空格字符。相反,空格字符將按編碼形式被渲染成 %20。
為支持像 HTML 格式的編碼,QUrlQuery 也從不將 %2B 序列解碼成 + 加號,也不會編碼 + 加號。事實上,在鍵、值或查詢字符串中找到的任何 %2B 或 + 序列,都準確像寫的一樣 (除將 %2b 大寫為 %2B 外)。
采用 QUrl::FullyDecoded 格式化,所有百分比編碼序列將被完全解碼,並使用 % 字符錶示自身。 QUrl::FullyDecoded 應小心使用,因為可能導緻數據丟失。見文檔編製 QUrl::FullyDecoded 瞭解可能丟失什麼數據的有關信息。
纔應該使用這種格式化模式,當在不期望百分比編碼的上下文中處理呈現給用戶的文本時。注意,QurlQuery setter 和查詢方法都不支持搭檔 QUrl::DecodedMode 剖析,所以使用 QUrl::FullyDecoded 以獲取鍵列錶可能導緻在對象中找不到鍵。
默認情況下,QUrlQuery 使用 = 等號分隔鍵與值,和使用 & 和號將鍵-值對彼此分隔。更改 QUrlQuery 用於剖析和重建查詢的定界符是可能的,通過調用 setQueryDelimiters ().
非標準定界符應從被稱為子定界符的 RFC 3986 中選取。它們是:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
不支持使用其它字符,且可能導緻意外行為。QUrlQuery 不驗證傳遞的是否為有效定界符。
另請參閱 QUrl .
拷貝內容從 other QUrlQuery 對象,包括查詢定界符。
構造 QUrlQuery 對象從 list 的鍵/值對。
該函數在 Qt 5.13 引入。
構造 QUrlQuery 對象和剖析 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 ().
Constructs a 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 ().
Constructs an empty QUrlQuery object. A query can be set afterwards by calling setQuery () or items can be added by using addQueryItem ().
另請參閱 setQuery () 和 addQueryItem ().
移動賦值 other 到此 QUrlQuery 實例。
該函數在 Qt 5.2 引入。
拷貝內容從 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== ().
返迴
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 引入。