6.0.0-rc4Source

QJsonValueConstRef Class

The QJsonValueConstRef class is a read-only reference to a value inside an array or object. More…

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

List of all members, including inherited members

Public Functions

QJsonValueConstRef(const QJsonValueConstRef &)
QJsonValue::Typetype() const
boolisNull() const
boolisBool() const
boolisDouble() const
boolisString() const
boolisArray() const
boolisObject() const
boolisUndefined() const
booltoBool(bool defaultValue = false) const
inttoInt(int defaultValue = 0) const
qint64toInteger(qint64 defaultValue = 0) const
doubletoDouble(double defaultValue = 0) const
QStringtoString() const
QStringtoString(const QString &defaultValue) const
QJsonArraytoArray() const
QJsonArraytoArray(const QJsonArray &defaultValue) const
QJsonObjecttoObject() const
QJsonObjecttoObject(const QJsonObject &defaultValue) const
QJsonValueoperator[](const QString &key) const
QJsonValueoperator[](QStringView key) const
QJsonValueoperator[](QLatin1StringView key) const
QJsonValueoperator[](K &&key) const
QJsonValueoperator[](qsizetype i) const

Detailed Description

Its instances are what the const iterators of QJsonArray and QJsonObject return. It reads the element each time it is used, so it behaves like a const QJsonValue & and converts to QJsonValue when copied into one.

See also QJsonValueRef and QJsonValue.

Differences from Qt

There is no conversion to QVariant. A reference does not keep the container alive, and reading through one after the container changed or was destroyed is not allowed.

Member Function Documentation

QJsonValueConstRef::QJsonValueConstRef(const QJsonValueConstRef &)

Creates a copy of the reference; both refer to the same element.

bool QJsonValueConstRef::isArray() const

Returns true if the element is an array.

bool QJsonValueConstRef::isBool() const

Returns true if the element is a bool.

bool QJsonValueConstRef::isDouble() const

Returns true if the element is a number.

bool QJsonValueConstRef::isNull() const

Returns true if the element is null.

bool QJsonValueConstRef::isObject() const

Returns true if the element is an object.

bool QJsonValueConstRef::isString() const

Returns true if the element is a string.

bool QJsonValueConstRef::isUndefined() const

Returns true if the element is undefined, which it is when the reference is out of range.

QJsonValue QJsonValueConstRef::operator[](const QString &key) const

Returns the value that key maps to if the element is an object, and an undefined value otherwise.

QJsonValue QJsonValueConstRef::operator[](QStringView key) const

This is an overloaded function.

QJsonValue QJsonValueConstRef::operator[](QLatin1StringView key) const

This is an overloaded function.

template <typename K, typename = std::enable_if_t<QtPrivate::IsJsonCString<K>>>QJsonValue QJsonValueConstRef::operator[](K &&key) const

This is an overloaded function.

Looks key up when it is a C string, such as a string literal.

QJsonValue QJsonValueConstRef::operator[](qsizetype i) const

This is an overloaded function.

Returns the item at index i if the element is an array, and an undefined value otherwise.

QJsonArray QJsonValueConstRef::toArray() const

Returns the element as an array, or an empty array if it is not one.

See also QJsonValue::toArray().

QJsonArray QJsonValueConstRef::toArray(const QJsonArray &defaultValue) const

This is an overloaded function.

Returns the element as an array, or defaultValue if it is not one.

bool QJsonValueConstRef::toBool(bool defaultValue = false) const

Returns the element as a bool, or defaultValue if it is not one.

See also QJsonValue::toBool().

double QJsonValueConstRef::toDouble(double defaultValue = 0) const

Returns the element as a double, or defaultValue if it is not a number.

See also QJsonValue::toDouble().

int QJsonValueConstRef::toInt(int defaultValue = 0) const

Returns the element as an int, or defaultValue if it is not a whole number that fits.

See also QJsonValue::toInt().

qint64 QJsonValueConstRef::toInteger(qint64 defaultValue = 0) const

Returns the element as a qint64, or defaultValue if it is not a whole number that fits.

See also QJsonValue::toInteger().

QJsonObject QJsonValueConstRef::toObject() const

Returns the element as an object, or an empty object if it is not one.

See also QJsonValue::toObject().

QJsonObject QJsonValueConstRef::toObject(const QJsonObject &defaultValue) const

This is an overloaded function.

Returns the element as an object, or defaultValue if it is not one.

QString QJsonValueConstRef::toString() const

Returns the element as a string, or a null string if it is not one.

See also QJsonValue::toString().

QString QJsonValueConstRef::toString(const QString &defaultValue) const

This is an overloaded function.

Returns the element as a string, or defaultValue if it is not one.

QJsonValue::Type QJsonValueConstRef::type() const

Returns the type of the element.