QJsonValueConstRef Class
The QJsonValueConstRef class is a read-only reference to a value inside an array or object. More…
| Header | #include <QJsonValueConstRef> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Inherited by | QJsonValueRef |
List of all members, including inherited members
Public Functions
| QJsonValueConstRef(const QJsonValueConstRef &) | |
| QJsonValue::Type | type() const |
| bool | isNull() const |
| bool | isBool() const |
| bool | isDouble() const |
| bool | isString() const |
| bool | isArray() const |
| bool | isObject() const |
| bool | isUndefined() const |
| bool | toBool(bool defaultValue = false) const |
| int | toInt(int defaultValue = 0) const |
| qint64 | toInteger(qint64 defaultValue = 0) const |
| double | toDouble(double defaultValue = 0) const |
| QString | toString() const |
| QString | toString(const QString &defaultValue) const |
| QJsonArray | toArray() const |
| QJsonArray | toArray(const QJsonArray &defaultValue) const |
| QJsonObject | toObject() const |
| QJsonObject | toObject(const QJsonObject &defaultValue) const |
| QJsonValue | operator[](const QString &key) const |
| QJsonValue | operator[](QStringView key) const |
| QJsonValue | operator[](QLatin1StringView key) const |
| QJsonValue | operator[](K &&key) const |
| QJsonValue | operator[](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.