![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qurlquery.h>
Public Types | |
typedef QSharedDataPointer< QUrlQueryPrivate > | DataPtr |
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< QPair< QString, QString > > list) | |
QUrlQuery (const QUrlQuery &other) | |
Copies the contents of the other QUrlQuery object, including the query delimiters. | |
QUrlQuery (QUrlQuery &&other) noexcept | |
QUrlQuery & | operator= (const QUrlQuery &other) |
Move-assigns other to this QUrlQuery instance. | |
~QUrlQuery () | |
Destroys this QUrlQuery object. | |
bool | operator== (const QUrlQuery &other) const |
Returns true if this object and the other object contain the same contents, in the same order, and use the same query delimiters. | |
bool | operator!= (const QUrlQuery &other) const |
Returns true if other is not equal to this QUrlQuery. | |
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< QPair< QString, QString > > &query) |
Sets the items in this QUrlQuery object to query. | |
QList< QPair< 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. | |
DataPtr & | data_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 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 |
\inmodule QtCore
The QUrlQuery class provides a way to manipulate a key-value pairs in a URL's query.
\reentrant
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.
Definition at line 76 of file qurlquery.h.
QUrlQuery::QUrlQuery | ( | ) |
Constructs an empty QUrlQuery object.
A query can be set afterwards by calling setQuery() or items can be added by using addQueryItem().
Definition at line 324 of file qurlquery.cpp.
|
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().
Definition at line 348 of file qurlquery.cpp.
References QUrl::hasQuery(), QUrl::query(), and url.
|
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 335 of file qurlquery.cpp.
Constructs a QUrlQuery object from the list of key/value pair.
Definition at line 25 of file qurlquery.h.
QUrlQuery::QUrlQuery | ( | const QUrlQuery & | other | ) |
Copies the contents of the other QUrlQuery object, including the query delimiters.
Definition at line 361 of file qurlquery.cpp.
|
noexcept |
Definition at line 371 of file qurlquery.cpp.
QUrlQuery::~QUrlQuery | ( | ) |
Destroys this QUrlQuery object.
Definition at line 396 of file qurlquery.cpp.
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.
Definition at line 682 of file qurlquery.cpp.
References QUrlQueryPrivate::addQueryItem().
Referenced by addAtForBoundingArea(), QGeoCodingManagerEngineMapbox::geocode(), QGeoCodingManagerEngineMapbox::geocode(), QPlaceManagerEngineNokiaV2::getPlaceContent(), QPlaceManagerEngineNokiaV2::getPlaceDetails(), QGeoCodingManagerEngineMapbox::reverseGeocode(), QPlaceManagerEngineNokiaV2::search(), PlaceManagerEngineEsri::search(), QPlaceManagerEngineOsm::search(), and QPlaceManagerEngineNokiaV2::searchSuggestions().
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.
Definition at line 722 of file qurlquery.cpp.
References QList< T >::at(), QUrlQueryPrivate::findRecodedKey(), QUrlQueryPrivate::itemList, QUrlQueryPrivate::recodeFromUser(), and QUrlQueryPrivate::recodeToUser().
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.
Definition at line 466 of file qurlquery.cpp.
References QList< T >::clear(), QSharedDataPointer< T >::constData(), and QUrlQueryPrivate::itemList.
Referenced by setQueryItems().
|
inline |
Definition at line 77 of file qurlquery.h.
References d.
|
inlinestaticconstexprnoexcept |
Returns the default character for separating keys-value pairs from each other, an ampersand ("&").
Definition at line 68 of file qurlquery.h.
Referenced by operator==(), and queryPairDelimiter().
|
inlinestaticconstexprnoexcept |
Returns the default character for separating keys from values in the query, an equal sign ("=").
Definition at line 67 of file qurlquery.h.
Referenced by operator==(), and queryValueDelimiter().
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.
Definition at line 662 of file qurlquery.cpp.
References QList< T >::constEnd(), QUrlQueryPrivate::findKey(), and QUrlQueryPrivate::itemList.
bool QUrlQuery::isDetached | ( | ) | const |
Definition at line 454 of file qurlquery.cpp.
References QBasicAtomicInteger< T >::loadRelaxed(), and QSharedData::ref.
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.
Definition at line 446 of file qurlquery.cpp.
References QList< T >::isEmpty(), and QUrlQueryPrivate::itemList.
|
inline |
Returns true
if other is not equal to this QUrlQuery.
Otherwise, returns false
.
Definition at line 39 of file qurlquery.h.
References other().
Move-assigns other to this QUrlQuery instance.
Copies the contents of the other QUrlQuery object, including the query delimiters.
Definition at line 380 of file qurlquery.cpp.
References other().
bool QUrlQuery::operator== | ( | const QUrlQuery & | other | ) | const |
Returns true
if this object and the other object contain the same contents, in the same order, and use the same query delimiters.
Definition at line 405 of file qurlquery.cpp.
References QSharedDataPointer< T >::data(), defaultQueryPairDelimiter(), defaultQueryValueDelimiter(), QUrlQueryPrivate::itemList, other(), QUrlQueryPrivate::pairDelimiter, and QUrlQueryPrivate::valueDelimiter.
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.
Definition at line 505 of file qurlquery.cpp.
References QList< T >::constBegin(), QList< T >::constEnd(), encode, QUrl::EncodeDelimiters, it, QUrlQueryPrivate::itemList, QUrlQueryPrivate::pairDelimiter, recodeAndAppend(), QSet< T >::size(), QChar::unicode(), and QUrlQueryPrivate::valueDelimiter.
QList< QPair< 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().
Definition at line 637 of file qurlquery.cpp.
References QList< T >::constBegin(), QList< T >::constEnd(), idempotentRecodeToUser(), it, QUrlQueryPrivate::itemList, qMakePair(), QUrlQueryPrivate::recodeToUser(), and QList< T >::size().
Referenced by QPlaceManagerEngineNokiaV2::search().
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().
Definition at line 702 of file qurlquery.cpp.
References QList< T >::constEnd(), QUrlQueryPrivate::findKey(), it, QUrlQueryPrivate::itemList, and QUrlQueryPrivate::recodeToUser().
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().
Definition at line 599 of file qurlquery.cpp.
References defaultQueryPairDelimiter(), and QUrlQueryPrivate::pairDelimiter.
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().
Definition at line 588 of file qurlquery.cpp.
References defaultQueryValueDelimiter(), and QUrlQueryPrivate::valueDelimiter.
Removes all the query string pairs whose key is equal to key from the URL.
Definition at line 764 of file qurlquery.cpp.
References QSharedDataPointer< T >::constData(), QSharedDataPointer< T >::data(), item, and QString::removeIf().
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().
Definition at line 746 of file qurlquery.cpp.
References QSharedDataPointer< T >::constData(), QSharedDataPointer< T >::data(), QSet< T >::end(), QSet< T >::erase(), and it.
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 478 of file qurlquery.cpp.
References QUrlQueryPrivate::setQuery().
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:
Use of other characters is not supported and may result in unexpected behaviour. This method does not verify that you passed a valid delimiter.
Definition at line 576 of file qurlquery.cpp.
References QUrlQueryPrivate::pairDelimiter, and QUrlQueryPrivate::valueDelimiter.
Sets the items in this QUrlQuery object to query.
The order of the elements in query is preserved.
Definition at line 616 of file qurlquery.cpp.
References QUrlQueryPrivate::addQueryItem(), clear(), QSet< T >::constBegin(), and it.
Swaps this URL query instance with other.
This function is very fast and never fails.
Definition at line 42 of file qurlquery.h.
|
inline |
Returns this QUrlQuery as a QString.
encoding can be used to specify the URL string encoding of the return value.
Definition at line 50 of file qurlquery.h.
|
related |
Returns the hash value for key, using seed to seed the calculation.
Definition at line 428 of file qurlquery.cpp.
|
friend |
Returns the hash value for key, using seed to seed the calculation.
Definition at line 428 of file qurlquery.cpp.
|
friend |
Definition at line 71 of file qurlquery.h.