Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QUrlQuery Class Reference

\inmodule QtCore More...

#include <qurlquery.h>

+ Collaboration diagram for QUrlQuery:

Public Types

typedef QSharedDataPointer< QUrlQueryPrivateDataPtr
 

Public Member Functions

 QUrlQuery ()
 Constructs an empty QUrlQuery object.
 
 QUrlQuery (const QUrl &url)
 Constructs a QUrlQuery object and parses the query string found in the url URL, using the default query delimiters.
 
 QUrlQuery (const QString &queryString)
 Constructs a QUrlQuery object and parses the queryString query string, using the default query delimiters.
 
 QUrlQuery (std::initializer_list< std::pair< QString, QString > > list)
 
 QUrlQuery (const QUrlQuery &other)
 Copies the contents of the other QUrlQuery object, including the query delimiters.
 
 QUrlQuery (QUrlQuery &&other) noexcept
 
QUrlQueryoperator= (const QUrlQuery &other)
 Move-assigns other to this QUrlQuery instance.
 
 ~QUrlQuery ()
 Destroys this QUrlQuery object.
 
void swap (QUrlQuery &other) noexcept
 Swaps this URL query instance with other.
 
bool isEmpty () const
 Returns true if this QUrlQuery object contains no key-value pairs, such as after being default-constructed or after parsing an empty query string.
 
bool isDetached () const
 
void clear ()
 Clears this QUrlQuery object by removing all of the key-value pairs currently stored.
 
QString query (QUrl::ComponentFormattingOptions encoding=QUrl::PrettyDecoded) const
 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.
 
void setQuery (const QString &queryString)
 Parses the query string in queryString and sets the internal items to the values found there.
 
QString toString (QUrl::ComponentFormattingOptions encoding=QUrl::PrettyDecoded) const
 Returns this QUrlQuery as a QString.
 
void setQueryDelimiters (QChar valueDelimiter, QChar pairDelimiter)
 Sets the characters used for delimiting between keys and values, and between key-value pairs in the URL's query string.
 
QChar queryValueDelimiter () const
 Returns the character used to delimit between keys and values when reconstructing the query string in query() or when parsing in setQuery().
 
QChar queryPairDelimiter () const
 Returns the character used to delimit between keys-value pairs when reconstructing the query string in query() or when parsing in setQuery().
 
void setQueryItems (const QList< std::pair< QString, QString > > &query)
 Sets the items in this QUrlQuery object to query.
 
QList< std::pair< QString, QString > > queryItems (QUrl::ComponentFormattingOptions encoding=QUrl::PrettyDecoded) const
 Returns the query string of the URL, as a map of keys and values, using the options specified in encoding to encode the items.
 
bool hasQueryItem (const QString &key) const
 Returns true if there is a query string pair whose key is equal to key from the URL.
 
void addQueryItem (const QString &key, const QString &value)
 Appends the pair key = value to the end of the query string of the URL.
 
void removeQueryItem (const QString &key)
 Removes the query string pair whose key is equal to key from the URL.
 
QString queryItemValue (const QString &key, QUrl::ComponentFormattingOptions encoding=QUrl::PrettyDecoded) const
 Returns the query value associated with key key from the URL, using the options specified in encoding to encode the return value.
 
QStringList allQueryItemValues (const QString &key, QUrl::ComponentFormattingOptions encoding=QUrl::PrettyDecoded) const
 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.
 
void removeAllQueryItems (const QString &key)
 Removes all the query string pairs whose key is equal to key from the URL.
 
DataPtrdata_ptr ()
 

Static Public Member Functions

static constexpr char16_t defaultQueryValueDelimiter () noexcept
 Returns the default character for separating keys from values in the query, an equal sign ("=").
 
static constexpr char16_t defaultQueryPairDelimiter () noexcept
 Returns the default character for separating keys-value pairs from each other, an ampersand ("&").
 

Friends

class QUrl
 
Q_CORE_EXPORT bool comparesEqual (const QUrlQuery &lhs, const QUrlQuery &rhs)
 
Q_CORE_EXPORT size_t qHash (const QUrlQuery &key, size_t seed) noexcept
 

Related Symbols

(Note that these are not member symbols.)

size_t qHash (const QUrlQuery &key, size_t seed) noexcept
 

Detailed Description

\inmodule QtCore

Since
5.0

The QUrlQuery class provides a way to manipulate a key-value pairs in a URL's query.

\reentrant

\compares equality

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.

Definition at line 19 of file qurlquery.h.

Member Typedef Documentation

◆ DataPtr

Definition at line 80 of file qurlquery.h.

Constructor & Destructor Documentation

◆ QUrlQuery() [1/6]

QUrlQuery::QUrlQuery ( )

Constructs an empty QUrlQuery object.

A query can be set afterwards by calling setQuery() or items can be added by using addQueryItem().

See also
setQuery(), addQueryItem()

Definition at line 326 of file qurlquery.cpp.

◆ QUrlQuery() [2/6]

QUrlQuery::QUrlQuery ( const QUrl & url)
explicit

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().

See also
QUrl::query()

Definition at line 350 of file qurlquery.cpp.

References QUrl::hasQuery(), QUrl::query(), and url.

+ Here is the call graph for this function:

◆ QUrlQuery() [3/6]

QUrlQuery::QUrlQuery ( const QString & queryString)
explicit

Constructs a 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().

Definition at line 337 of file qurlquery.cpp.

◆ QUrlQuery() [4/6]

QUrlQuery::QUrlQuery ( std::initializer_list< std::pair< QString, QString > > list)
inline
Since
5.13

Constructs a QUrlQuery object from the list of key/value pair.

Definition at line 25 of file qurlquery.h.

References item, and list.

◆ QUrlQuery() [5/6]

QUrlQuery::QUrlQuery ( const QUrlQuery & other)

Copies the contents of the other QUrlQuery object, including the query delimiters.

Definition at line 363 of file qurlquery.cpp.

◆ QUrlQuery() [6/6]

QUrlQuery::QUrlQuery ( QUrlQuery && other)
noexcept
Since
6.5 Moves the contents of the other QUrlQuery object, including the query delimiters.

Definition at line 373 of file qurlquery.cpp.

◆ ~QUrlQuery()

QUrlQuery::~QUrlQuery ( )

Destroys this QUrlQuery object.

Definition at line 398 of file qurlquery.cpp.

Member Function Documentation

◆ addQueryItem()

void QUrlQuery::addQueryItem ( const QString & key,
const QString & value )

Appends the pair 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.

Note
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.
The key and value strings are expected to be in percent-encoded form.
See also
hasQueryItem(), queryItemValue()

Definition at line 687 of file qurlquery.cpp.

References QUrlQueryPrivate::addQueryItem().

Referenced by addAtForBoundingArea(), QGeoCodingManagerEngineMapbox::geocode(), GeoCodingManagerEngineEsri::geocode(), QGeoCodingManagerEngineMapbox::geocode(), QGeoCodingManagerEngineOsm::geocode(), QPlaceManagerEngineNokiaV2::getPlaceContent(), QPlaceManagerEngineNokiaV2::getPlaceDetails(), QGeoRouteParserOsrmV5Private::requestUrl(), QGeoRouteParserOsrmV4Private::requestUrl(), GeoCodingManagerEngineEsri::reverseGeocode(), QGeoCodingManagerEngineMapbox::reverseGeocode(), QGeoCodingManagerEngineOsm::reverseGeocode(), QPlaceManagerEngineNokiaV2::search(), PlaceManagerEngineEsri::search(), QPlaceManagerEngineOsm::search(), and QPlaceManagerEngineNokiaV2::searchSuggestions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ allQueryItemValues()

QStringList QUrlQuery::allQueryItemValues ( const QString & key,
QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded ) const

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.

Note
The key is expected to be in percent-encoded form.
See also
queryItemValue(), addQueryItem()

Definition at line 727 of file qurlquery.cpp.

References QList< T >::at(), QUrlQueryPrivate::findRecodedKey(), QUrlQueryPrivate::itemList, QUrlQueryPrivate::recodeFromUser(), and QUrlQueryPrivate::recodeToUser().

+ Here is the call graph for this function:

◆ clear()

void QUrlQuery::clear ( )

Clears this 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.

See also
isEmpty(), setQueryDelimiters()

Definition at line 471 of file qurlquery.cpp.

References QList< T >::clear(), QSharedDataPointer< T >::constData(), and QUrlQueryPrivate::itemList.

Referenced by QNetworkRequestFactory::clearQueryParameters(), and setQueryItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ data_ptr()

DataPtr & QUrlQuery::data_ptr ( )
inline

Definition at line 81 of file qurlquery.h.

References d.

◆ defaultQueryPairDelimiter()

QUrlQuery::defaultQueryPairDelimiter ( )
inlinestaticconstexprnoexcept

Returns the default character for separating keys-value pairs from each other, an ampersand ("&").

Note
Prior to Qt 6, this function returned QChar.
See also
setQueryDelimiters(), queryPairDelimiter(), defaultQueryValueDelimiter()

Definition at line 70 of file qurlquery.h.

Referenced by queryPairDelimiter().

+ Here is the caller graph for this function:

◆ defaultQueryValueDelimiter()

QUrlQuery::defaultQueryValueDelimiter ( )
inlinestaticconstexprnoexcept

Returns the default character for separating keys from values in the query, an equal sign ("=").

Note
Prior to Qt 6, this function returned QChar.
See also
setQueryDelimiters(), queryValueDelimiter(), defaultQueryPairDelimiter()

Definition at line 69 of file qurlquery.h.

Referenced by queryValueDelimiter().

+ Here is the caller graph for this function:

◆ hasQueryItem()

bool QUrlQuery::hasQueryItem ( const QString & key) const

Returns true if there is a query string pair whose key is equal to key from the URL.

Note
The key expected to be in percent-encoded form.
See also
addQueryItem(), queryItemValue()

Definition at line 667 of file qurlquery.cpp.

References QList< T >::constEnd(), QUrlQueryPrivate::findKey(), and QUrlQueryPrivate::itemList.

+ Here is the call graph for this function:

◆ isDetached()

bool QUrlQuery::isDetached ( ) const

Definition at line 459 of file qurlquery.cpp.

References QBasicAtomicInteger< T >::loadRelaxed(), and QSharedData::ref.

+ Here is the call graph for this function:

◆ isEmpty()

bool QUrlQuery::isEmpty ( ) const

Returns true if this QUrlQuery object contains no key-value pairs, such as after being default-constructed or after parsing an empty query string.

See also
setQuery(), clear()

Definition at line 451 of file qurlquery.cpp.

References QList< T >::isEmpty(), and QUrlQueryPrivate::itemList.

Referenced by QNetworkRequestFactory::clearQueryParameters(), and QNetworkRequestFactoryPrivate::requestUrl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

QUrlQuery & QUrlQuery::operator= ( const QUrlQuery & other)

Move-assigns other to this QUrlQuery instance.

Copies the contents of the other QUrlQuery object, including the query delimiters.

Since
5.2

Definition at line 382 of file qurlquery.cpp.

References other().

+ Here is the call graph for this function:

◆ query()

QString QUrlQuery::query ( QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const

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 parameter.

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.

See also
setQuery(), QUrl::setQuery(), QUrl::fragment(), {encoding}{Encoding}

Definition at line 510 of file qurlquery.cpp.

References QList< T >::constBegin(), QList< T >::constEnd(), encode, QUrl::EncodeDelimiters, it, QUrlQueryPrivate::itemList, QUrlQueryPrivate::pairDelimiter, recodeAndAppend(), QSet< T >::size(), and QUrlQueryPrivate::valueDelimiter.

+ Here is the call graph for this function:

◆ queryItems()

QList< std::pair< QString, QString > > QUrlQuery::queryItems ( QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const

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().

See also
setQueryItems(), {encoding}{Encoding}

Definition at line 642 of file qurlquery.cpp.

References QList< T >::constBegin(), QList< T >::constEnd(), idempotentRecodeToUser(), it, QUrlQueryPrivate::itemList, QUrlQueryPrivate::recodeToUser(), and QList< T >::size().

Referenced by QNetworkRequestFactoryPrivate::requestUrl(), and QPlaceManagerEngineNokiaV2::search().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ queryItemValue()

QString QUrlQuery::queryItemValue ( const QString & key,
QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded ) const

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().

Note
The key is expected to be in percent-encoded form.
See also
addQueryItem(), allQueryItemValues(), {encoding}{Encoding}

Definition at line 707 of file qurlquery.cpp.

References QList< T >::constEnd(), QUrlQueryPrivate::findKey(), it, QUrlQueryPrivate::itemList, and QUrlQueryPrivate::recodeToUser().

+ Here is the call graph for this function:

◆ queryPairDelimiter()

QChar QUrlQuery::queryPairDelimiter ( ) const

Returns the character used to delimit between keys-value pairs when reconstructing the query string in query() or when parsing in setQuery().

See also
setQueryDelimiters(), queryValueDelimiter()

Definition at line 604 of file qurlquery.cpp.

References defaultQueryPairDelimiter(), and QUrlQueryPrivate::pairDelimiter.

+ Here is the call graph for this function:

◆ queryValueDelimiter()

QChar QUrlQuery::queryValueDelimiter ( ) const

Returns the character used to delimit between keys and values when reconstructing the query string in query() or when parsing in setQuery().

See also
setQueryDelimiters(), queryPairDelimiter()

Definition at line 593 of file qurlquery.cpp.

References defaultQueryValueDelimiter(), and QUrlQueryPrivate::valueDelimiter.

+ Here is the call graph for this function:

◆ removeAllQueryItems()

void QUrlQuery::removeAllQueryItems ( const QString & key)

Removes all the query string pairs whose key is equal to key from the URL.

Note
The key is expected to be in percent-encoded form.
See also
removeQueryItem()

Definition at line 769 of file qurlquery.cpp.

References QSharedDataPointer< T >::constData(), QSharedDataPointer< T >::data(), and item.

+ Here is the call graph for this function:

◆ removeQueryItem()

void QUrlQuery::removeQueryItem ( const QString & key)

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().

Note
The key is expected to be in percent-encoded form.
See also
removeAllQueryItems()

Definition at line 751 of file qurlquery.cpp.

References QSharedDataPointer< T >::constData(), QSharedDataPointer< T >::data(), QSet< T >::end(), QSet< T >::erase(), and it.

+ Here is the call graph for this function:

◆ setQuery()

void QUrlQuery::setQuery ( const QString & queryString)

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.

Definition at line 483 of file qurlquery.cpp.

References QUrlQueryPrivate::setQuery().

+ Here is the call graph for this function:

◆ setQueryDelimiters()

void QUrlQuery::setQueryDelimiters ( QChar valueDelimiter,
QChar pairDelimiter )

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().

If valueDelimiter is set to ',' and pairDelimiter is ';', the above query string would instead be represented like this:

Note
Non-standard delimiters should be chosen from among what RFC 3986 calls "sub-delimiters". They are:
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter * sub

Use of other characters is not supported and may result in unexpected behavior. This method does not verify that you passed a valid delimiter.

See also
queryValueDelimiter(), queryPairDelimiter()

Definition at line 581 of file qurlquery.cpp.

References QUrlQueryPrivate::pairDelimiter, and QUrlQueryPrivate::valueDelimiter.

◆ setQueryItems()

void QUrlQuery::setQueryItems ( const QList< std::pair< QString, QString > > & query)

Sets the items in this QUrlQuery object to query.

The order of the elements in query is preserved.

Note
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.
The keys and values are expected to be in percent-encoded form.
See also
queryItems(), isEmpty()

Definition at line 621 of file qurlquery.cpp.

References QUrlQueryPrivate::addQueryItem(), clear(), QSet< T >::constBegin(), and it.

+ Here is the call graph for this function:

◆ swap()

void QUrlQuery::swap ( QUrlQuery & other)
inlinenoexcept

Swaps this URL query instance with other.

This function is very fast and never fails.

Definition at line 44 of file qurlquery.h.

References d, and other().

+ Here is the call graph for this function:

◆ toString()

QString QUrlQuery::toString ( QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
inline

Returns this QUrlQuery as a QString.

encoding can be used to specify the URL string encoding of the return value.

Definition at line 52 of file qurlquery.h.

Friends And Related Symbol Documentation

◆ comparesEqual

Q_CORE_EXPORT bool comparesEqual ( const QUrlQuery & lhs,
const QUrlQuery & rhs )
friend

Definition at line 410 of file qurlquery.cpp.

◆ qHash() [1/2]

size_t qHash ( const QUrlQuery & key,
size_t seed )
related
Since
5.6

Returns the hash value for key, using seed to seed the calculation.

Definition at line 433 of file qurlquery.cpp.

◆ qHash [2/2]

size_t qHash ( const QUrlQuery & key,
size_t seed = 0 )
friend
Since
5.6

Returns the hash value for key, using seed to seed the calculation.

Definition at line 433 of file qurlquery.cpp.

◆ QUrl

friend class QUrl
friend

Definition at line 75 of file qurlquery.h.


The documentation for this class was generated from the following files: