6.0.0-rc4Source

QUrlQuery Class

The QUrlQuery class reads and builds the key-value pairs of a URL query. More…

Header#include <QUrlQuery>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QUrlQuery()
QUrlQuery(const QUrl &url)
QUrlQuery(const QString &queryString)
QUrlQuery(std::initializer_list<std::pair<QString, QString>> list)
boolisEmpty() const
voidclear()
voidsetQuery(const QString &queryString)
QStringquery(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
QStringtoString(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
voidsetQueryItems(const QList<std::pair<QString, QString>> &query)
QList<std::pair<QString, QString>>queryItems(QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
boolhasQueryItem(const QString &key) const
voidaddQueryItem(const QString &key, const QString &value)
voidremoveQueryItem(const QString &key)
QStringqueryItemValue(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
QStringListallQueryItemValues(const QString &key, QUrl::ComponentFormattingOptions encoding = QUrl::PrettyDecoded) const
voidremoveAllQueryItems(const QString &key)
voidsetQueryDelimiters(QChar valueDelimiter, QChar pairDelimiter)
QCharqueryValueDelimiter() const
QCharqueryPairDelimiter() const
voidswap(QUrlQuery &other)

Static Public Members

Detailed Description

QUrlQuery query;
query.addQueryItem("q", "a b");
query.addQueryItem("page", "2");

QUrl url("http://example.com/search");
url.setQuery(query.query(QUrl::FullyEncoded));
url.toEncoded();    // "http://example.com/search?q=a%20b&page=2"

Pairs are separated by & and keys from values by = unless setQueryDelimiters() chooses other characters, such as ; for queries in the older HTML style.

See also QUrl.

Differences from Qt

Items are std::pair rather than QPair. The delimiters must be ASCII characters.

Member Function Documentation

QUrlQuery::QUrlQuery()

Constructs an empty query.

[explicit] QUrlQuery::QUrlQuery(const QUrl &url)

Constructs a query from the query part of url.

[explicit] QUrlQuery::QUrlQuery(const QString &queryString)

Constructs a query by parsing queryString.

See also setQuery().

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

Constructs a query from the key-value pairs in list.

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

Appends an item with the given key and value. Existing items with the same key are kept.

See also removeQueryItem().

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

Returns the values of every item with the given key, formatted according to encoding.

See also queryItemValue().

void QUrlQuery::clear()

Removes every item.

[static, constexpr] char16_t QUrlQuery::defaultQueryPairDelimiter()

Returns the default pair delimiter, &.

[static, constexpr] char16_t QUrlQuery::defaultQueryValueDelimiter()

Returns the default value delimiter, =.

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

Returns true if there is an item with the given key.

See also queryItemValue().

bool QUrlQuery::isEmpty() const

Returns true if there are no items.

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

Returns the query as text, formatted according to encoding.

See also setQuery().

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

Returns the items as key-value pairs, in order, with keys and values formatted according to encoding.

See also setQueryItems().

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

Returns the value of the first item with the given key, formatted according to encoding, or an empty string if there is none.

See also allQueryItemValues().

QChar QUrlQuery::queryPairDelimiter() const

Returns the character that separates the pairs; & unless setQueryDelimiters() changed it.

QChar QUrlQuery::queryValueDelimiter() const

Returns the character that separates a key from its value; = unless setQueryDelimiters() changed it.

void QUrlQuery::removeAllQueryItems(const QString &key)

Removes every item with the given key.

See also removeQueryItem().

void QUrlQuery::removeQueryItem(const QString &key)

Removes the first item with the given key.

See also removeAllQueryItems().

void QUrlQuery::setQuery(const QString &queryString)

Replaces the contents by parsing queryString, whose keys and values may be percent-encoded.

See also query().

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

Sets the characters that separate a key from its value to valueDelimiter and the pairs from each other to pairDelimiter. They apply to setQuery() and query() calls that follow; the items are kept. Both must be ASCII characters, and different.

QUrlQuery q;
q.setQueryDelimiters(u':', u';');
q.setQuery("a:1;b:2");
q.queryItemValue("b");   // "2"

See also queryValueDelimiter() and queryPairDelimiter().

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

Replaces the items with the key-value pairs in query.

See also queryItems().

void QUrlQuery::swap(QUrlQuery &other)

Swaps this query with other. This operation is very fast and never fails.

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

Returns the query as text, formatted according to encoding. This is the same as query().