Skip to content

PythonQt.QtCore.QUrlQuery

QUrlQuery

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

It is used to parse the query strings found in URLs like the following:

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() from the individual components of the query.

The most common way of parsing a query string is to initialize it in the constructor by passing it the query string. Otherwise, the 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 the setQueryDelimiters() function.

The encoded query string can be obtained again using query(). This will take all the internally-stored items and encode the string using the delimiters.

Encoding

All of the getter methods in QUrlQuery support an optional parameter of type QUrl::ComponentFormattingOptions, including query(), which dictate how to encode the data in question. Except for QUrl::FullyDecoded, 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".

Handling of spaces and plus ("+")

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, 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").

Full decoding

With QUrl::FullyDecoded formatting, all percent-encoded sequences will be decoded fully and the '%' character is used to represent itself. QUrl::FullyDecoded should be used with care, since it may cause data loss. See the documentation of QUrl::FullyDecoded for information on what data may be lost.

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 parsing, so using QUrl::FullyDecoded to obtain a listing of keys may result in keys not found in the object.

Non-standard delimiters

By default, 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().

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. QUrlQuery does not verify that you passed a valid delimiter.

Source: https://doc.qt.io/archives/qt-5.15/qurlquery.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
addQueryItem function (self, key: str, value: str) -> None X.addQueryItem(key, value)
allQueryItemValues function (self, key: str, encoding: Any) -> tuple X.allQueryItemValues(key, encoding) -> tuple
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
clear function (self) -> None Clears this [QUrlQuery](https://doc.qt.io/archives/qt-5.15/qurlquery.html) object by removing all of the key-value pairs currently stored.
defaultQueryPairDelimiter function (self) -> str Returns the default character for separating keys-value pairs from each other, an ampersand ("\&").
defaultQueryValueDelimiter function (self) -> str Returns the default character for separating keys from values in the query, an equal sign ("\=").
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
hasQueryItem function (self, key: str) -> bool X.hasQueryItem(key) -> bool
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isEmpty function (self) -> bool X.isEmpty() -> bool
operator_assign function (self, other: Any) -> Any X.operator_assign(other) -> PythonQt.QtCore.QUrlQuery
query function (self, encoding: Any) -> str X.query(encoding) -> str
queryItemValue function (self, key: str, encoding: Any) -> str X.queryItemValue(key, encoding) -> str
queryItems function (self, encoding: Any) -> tuple X.queryItems(encoding) -> tuple
queryPairDelimiter function (self) -> str Returns the character used to delimit between keys-value pairs when reconstructing the query string in [query](https://doc.qt.io/archives/qt-5.15/qurlquery.html#query)() or when parsing in…
queryValueDelimiter function (self) -> str Returns the character used to delimit between keys and values when reconstructing the query string in [query](https://doc.qt.io/archives/qt-5.15/qurlquery.html#query)() or when parsing in…
removeAllQueryItems function (self, key: str) -> None Removes all the query string pairs whose key is equal to key from the URL.
removeQueryItem function (self, key: str) -> None Removes the query string pair whose key is equal to key from the URL.
setQuery function (self, queryString: str) -> None Parses the query string in queryString and sets the internal items to the values found there.
setQueryDelimiters function (self, valueDelimiter: str, pairDelimiter: str) -> None X.setQueryDelimiters(valueDelimiter, pairDelimiter)
setQueryItems function (self, query: Any) -> None Sets the items in this [QUrlQuery](https://doc.qt.io/archives/qt-5.15/qurlquery.html) object to query.
swap function (self, other: Any) -> None Swaps this URL query instance with other.
toString function (self, encoding: Any) -> str X.toString(encoding) -> str