![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore\reentrant More...
#include <qjsonarray.h>
Classes | |
class | const_iterator |
\inmodule QtCore More... | |
class | iterator |
\inmodule QtCore More... | |
Public Types | |
typedef iterator | Iterator |
Qt-style synonym for QJsonArray::iterator. | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QJsonArray::const_iterator. | |
typedef qsizetype | size_type |
Typedef for qsizetype. | |
typedef QJsonValue | value_type |
Typedef for QJsonValue. | |
typedef value_type * | pointer |
Typedef for QJsonValue *. | |
typedef const value_type * | const_pointer |
Typedef for const QJsonValue *. | |
typedef QJsonValueRef | reference |
Typedef for QJsonValue &. | |
typedef QJsonValue | const_reference |
Typedef for const QJsonValue &. | |
typedef qsizetype | difference_type |
Typedef for qsizetype. | |
Public Member Functions | |
QJsonArray () | |
Creates an empty array. | |
QJsonArray (std::initializer_list< QJsonValue > args) | |
~QJsonArray () | |
Deletes the array. | |
QJsonArray (const QJsonArray &other) noexcept | |
Creates a copy of other. | |
QJsonArray & | operator= (const QJsonArray &other) noexcept |
Assigns other to this array. | |
QJsonArray (QJsonArray &&other) noexcept | |
QJsonArray & | operator= (QJsonArray &&other) noexcept |
QVariantList | toVariantList () const |
Converts this object to a QVariantList. | |
qsizetype | size () const |
Returns the number of values stored in the array. | |
qsizetype | count () const |
Same as size(). | |
bool | isEmpty () const |
Returns true if the object is empty. | |
QJsonValue | at (qsizetype i) const |
Returns a QJsonValue representing the value for index i. | |
QJsonValue | first () const |
Returns the first value stored in the array. | |
QJsonValue | last () const |
Returns the last value stored in the array. | |
void | prepend (const QJsonValue &value) |
Inserts value at the beginning of the array. | |
void | append (const QJsonValue &value) |
Inserts value at the end of the array. | |
void | removeAt (qsizetype i) |
Removes the value at index position i. | |
QJsonValue | takeAt (qsizetype i) |
Removes the item at index position i and returns it. | |
void | removeFirst () |
Removes the first item in the array. | |
void | removeLast () |
Removes the last item in the array. | |
void | insert (qsizetype i, const QJsonValue &value) |
Inserts value at index position i in the array. | |
void | replace (qsizetype i, const QJsonValue &value) |
Replaces the item at index position i with value. | |
bool | contains (const QJsonValue &element) const |
Returns true if the array contains an occurrence of value, otherwise false . | |
QJsonValueRef | operator[] (qsizetype i) |
Returns the value at index position i as a modifiable reference. | |
QJsonValue | operator[] (qsizetype i) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as at(). | |
bool | operator== (const QJsonArray &other) const |
Returns true if this array is equal to other. | |
bool | operator!= (const QJsonArray &other) const |
Returns true if this array is not equal to other. | |
void | swap (QJsonArray &other) noexcept |
iterator | begin () |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array. | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constBegin () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array. | |
const_iterator | cbegin () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array. | |
iterator | end () |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array. | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constEnd () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array. | |
const_iterator | cend () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array. | |
iterator | insert (iterator before, const QJsonValue &value) |
Inserts value before the position pointed to by before, and returns an iterator pointing to the newly inserted item. | |
iterator | erase (iterator it) |
Removes the item pointed to by it, and returns an iterator pointing to the next item. | |
QJsonArray | operator+ (const QJsonValue &v) const |
Returns an array that contains all the items in this array followed by the provided value. | |
QJsonArray & | operator+= (const QJsonValue &v) |
Appends value to the array, and returns a reference to the array itself. | |
QJsonArray & | operator<< (const QJsonValue &v) |
Appends value to the array, and returns a reference to the array itself. | |
void | push_back (const QJsonValue &t) |
This function is provided for STL compatibility. | |
void | push_front (const QJsonValue &t) |
This function is provided for STL compatibility. | |
void | pop_front () |
This function is provided for STL compatibility. | |
void | pop_back () |
This function is provided for STL compatibility. | |
bool | empty () const |
This function is provided for STL compatibility. | |
Static Public Member Functions | |
static QJsonArray | fromStringList (const QStringList &list) |
Converts the string list list to a QJsonArray. | |
static QJsonArray | fromVariantList (const QVariantList &list) |
Converts the variant list list to a QJsonArray. | |
Friends | |
class | iterator |
class | const_iterator |
class | QJsonValue |
class | QJsonValueConstRef |
class | QJsonValueRef |
class | QJsonPrivate::Value |
class | QJsonDocument |
class | QCborArray |
Q_CORE_EXPORT QDebug | operator<< (QDebug, const QJsonArray &) |
\inmodule QtCore
\reentrant
The QJsonArray class encapsulates a JSON array.
A JSON array is a list of values. The list can be manipulated by inserting and removing QJsonValue's from the array.
A QJsonArray can be converted to and from a QVariantList. You can query the number of entries with size(), insert(), and removeAt() entries from it and iterate over its content using the standard C++ iterator pattern.
QJsonArray is an implicitly shared class and shares the data with the document it has been created from as long as it is not being modified.
You can convert the array to and from text based JSON through QJsonDocument.
Definition at line 17 of file qjsonarray.h.
Typedef for const QJsonValue *.
Provided for STL compatibility.
Definition at line 214 of file qjsonarray.h.
Typedef for const QJsonValue &.
Provided for STL compatibility.
Definition at line 216 of file qjsonarray.h.
Qt-style synonym for QJsonArray::const_iterator.
Definition at line 195 of file qjsonarray.h.
Qt-style synonym for QJsonArray::iterator.
Definition at line 194 of file qjsonarray.h.
Typedef for QJsonValue *.
Provided for STL compatibility.
Definition at line 213 of file qjsonarray.h.
Typedef for QJsonValue &.
Provided for STL compatibility.
Definition at line 215 of file qjsonarray.h.
Typedef for QJsonValue.
Provided for STL compatibility.
Definition at line 212 of file qjsonarray.h.
|
default |
Creates an empty array.
QJsonArray::QJsonArray | ( | std::initializer_list< QJsonValue > | args | ) |
QJsonArray can be constructed in a way similar to JSON notation, for example:
Definition at line 130 of file qjsonarray.cpp.
References append(), arg, and args.
|
default |
Deletes the array.
|
defaultnoexcept |
Creates a copy of other.
Since QJsonArray is implicitly shared, the copy is shallow as long as the object doesn't get modified.
|
noexcept |
Move-constructs a QJsonArray from other.
Definition at line 149 of file qjsonarray.cpp.
References other().
void QJsonArray::append | ( | const QJsonValue & | value | ) |
Inserts value at the end of the array.
Definition at line 321 of file qjsonarray.cpp.
References insert().
Referenced by QJsonArray(), addDeco(), blockMemberObject(), builtinObject(), exportArrayOfArrayOfPositions(), exportArrayOfPositions(), exportFeatureCollection(), QGeoJson::exportGeoJson(), exportGeometryCollection(), exportMultiPolygon(), Moc::generate(), inOutObject(), QQmlJSLinter::lintFile(), QQmlJSLinter::lintModule(), QShaderDescriptionPrivate::makeDoc(), readFromDevice(), ClassDef::toJson(), and EnumDef::toJson().
QJsonValue QJsonArray::at | ( | qsizetype | i | ) | const |
Returns a QJsonValue representing the value for index i.
The returned QJsonValue is Undefined
, if i is out of bounds.
Definition at line 272 of file qjsonarray.cpp.
References QJsonPrivate::Value::fromTrustedCbor(), i, QJsonValue, and QJsonValue::Undefined.
Referenced by constructRoute(), QDefaultOutputMapping::load(), QGtk3Json::load(), QKmsScreenConfig::loadConfig(), QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(), QJsonValue::operator[](), parseBoundingBox(), parseCategories(), parseContactDetails(), parseCoordinate(), QMapboxCommon::parseGeoLocation(), QGeoRouteParserOsrmV5Private::parseReply(), QGeoRouteParserOsrmV4Private::parseReply(), and scanImports().
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.
Definition at line 180 of file qjsonarray.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 181 of file qjsonarray.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.
Definition at line 183 of file qjsonarray.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.
Definition at line 187 of file qjsonarray.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.
Definition at line 182 of file qjsonarray.h.
Referenced by contains(), contains(), matches(), and readGpuFeatures().
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.
Definition at line 186 of file qjsonarray.h.
Referenced by contains(), contains(), matches(), and readGpuFeatures().
bool QJsonArray::contains | ( | const QJsonValue & | value | ) | const |
Returns true
if the array contains an occurrence of value, otherwise false
.
Definition at line 434 of file qjsonarray.cpp.
|
inline |
Same as size().
Definition at line 42 of file qjsonarray.h.
Referenced by constructRoute(), QGeoTiledMappingManagerEngineNokia::loadCopyrightsDescriptorsFromJson(), parseBoundingBox(), parseCategories(), parseContactDetails(), QGeoRouteParserOsrmV4Private::parseReply(), runQmlImportScanner(), and scanImports().
|
inline |
This function is provided for STL compatibility.
It is equivalent to isEmpty() and returns true
if the array is empty.
Definition at line 210 of file qjsonarray.h.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.
Definition at line 184 of file qjsonarray.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 185 of file qjsonarray.h.
|
inline |
Removes the item pointed to by it, and returns an iterator pointing to the next item.
Definition at line 190 of file qjsonarray.h.
References it.
QJsonValue QJsonArray::first | ( | ) | const |
Returns the first value stored in the array.
Same as at(0)
.
Definition at line 287 of file qjsonarray.cpp.
References at.
Referenced by ClassDef::toJson().
|
static |
Converts the string list list to a QJsonArray.
The values in list will be converted to JSON values.
Definition at line 206 of file qjsonarray.cpp.
References QList< T >::constBegin(), QList< T >::constEnd(), it, and list.
Referenced by QJsonValue::fromVariant().
|
static |
Converts the variant list list to a QJsonArray.
The QVariant values in list will be converted to JSON values.
Definition at line 224 of file qjsonarray.cpp.
Referenced by QJsonDocument::fromVariant(), and QJsonValue::fromVariant().
|
inline |
Inserts value before the position pointed to by before, and returns an iterator pointing to the newly inserted item.
Definition at line 188 of file qjsonarray.h.
References insert().
void QJsonArray::insert | ( | qsizetype | i, |
const QJsonValue & | value | ||
) |
Inserts value at index position i in the array.
If i is 0
, the value is prepended to the array. If i is size(), the value is appended to the array.
Definition at line 386 of file qjsonarray.cpp.
References elements, QCborValue::fromJsonValue(), i, Q_ASSERT, and QJsonValue::Undefined.
Referenced by append(), prepend(), readGpuFeatures(), and QGtk3Json::save().
bool QJsonArray::isEmpty | ( | ) | const |
Returns true
if the object is empty.
This is the same as size() == 0.
Definition at line 261 of file qjsonarray.cpp.
Referenced by Moc::generate(), QShaderDescriptionPrivate::makeDoc(), BacktraceJob::run(), ClassDef::toJson(), and EnumDef::toJson().
QJsonValue QJsonArray::last | ( | ) | const |
Returns the last value stored in the array.
Same as {at(size() - 1)}.
Definition at line 299 of file qjsonarray.cpp.
References at.
bool QJsonArray::operator!= | ( | const QJsonArray & | other | ) | const |
Returns true
if this array is not equal to other.
Definition at line 497 of file qjsonarray.cpp.
References other().
|
inline |
Returns an array that contains all the items in this array followed by the provided value.
Definition at line 198 of file qjsonarray.h.
|
inline |
Appends value to the array, and returns a reference to the array itself.
Definition at line 200 of file qjsonarray.h.
References append().
|
inline |
Appends value to the array, and returns a reference to the array itself.
Definition at line 202 of file qjsonarray.h.
References append().
|
defaultnoexcept |
Assigns other to this array.
|
inlinenoexcept |
Move-assigns other to this array.
Definition at line 31 of file qjsonarray.h.
References other(), and swap().
bool QJsonArray::operator== | ( | const QJsonArray & | other | ) | const |
Returns true
if this array is equal to other.
Definition at line 475 of file qjsonarray.cpp.
QJsonValueRef QJsonArray::operator[] | ( | qsizetype | i | ) |
Returns the value at index position i as a modifiable reference.
i must be a valid index position in the array (i.e., {0 <= i < size()}).
The return value is of type QJsonValueRef, a helper class for QJsonArray and QJsonObject. When you get an object of type QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference.
Definition at line 456 of file qjsonarray.cpp.
References elements, i, Q_ASSERT, and QJsonValueRef.
QJsonValue QJsonArray::operator[] | ( | qsizetype | i | ) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as at().
Definition at line 467 of file qjsonarray.cpp.
|
inline |
This function is provided for STL compatibility.
It is equivalent to removeLast(). The array must not be empty. If the array can be empty, call isEmpty() before calling this function.
Definition at line 209 of file qjsonarray.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to removeFirst(). The array must not be empty. If the array can be empty, call isEmpty() before calling this function.
Definition at line 208 of file qjsonarray.h.
void QJsonArray::prepend | ( | const QJsonValue & | value | ) |
Inserts value at the beginning of the array.
This is the same as {insert(0, value)} and will prepend value to the array.
Definition at line 311 of file qjsonarray.cpp.
References insert().
|
inline |
This function is provided for STL compatibility.
It is equivalent to \l{QJsonArray::append()}{append(value)} and will append value to the array.
Definition at line 206 of file qjsonarray.h.
References append().
Referenced by QV4DataCollector::buildFrame(), QV4DebuggerAgent::debuggerPaused(), and BacktraceJob::run().
|
inline |
This function is provided for STL compatibility.
It is equivalent to \l{QJsonArray::prepend()}{prepend(value)} and will prepend value to the array.
Definition at line 207 of file qjsonarray.h.
References prepend().
|
inline |
Removes the first item in the array.
Calling this function is equivalent to calling {removeAt(0)}. The array must not be empty. If the array can be empty, call isEmpty() before calling this function.
Definition at line 53 of file qjsonarray.h.
|
inline |
Removes the last item in the array.
Calling this function is equivalent to calling {removeAt(size() - 1)}. The array must not be empty. If the array can be empty, call isEmpty() before calling this function.
Definition at line 54 of file qjsonarray.h.
void QJsonArray::replace | ( | qsizetype | i, |
const QJsonValue & | value | ||
) |
Replaces the item at index position i with value.
i must be a valid index position in the array (i.e., {0 <= i < size()}).
Definition at line 422 of file qjsonarray.cpp.
References elements, QCborValue::fromJsonValue(), i, and Q_ASSERT.
qsizetype QJsonArray::size | ( | ) | const |
Returns the number of values stored in the array.
Definition at line 243 of file qjsonarray.cpp.
Referenced by QDefaultOutputMapping::load(), QGtk3Json::load(), QKmsScreenConfig::loadConfig(), QGeoRouteParserOsrmV5Private::parseReply(), BacktraceJob::run(), and ClassDef::toJson().
|
inlinenoexcept |
Swaps the array other with this. This operation is very fast and never fails.
Definition at line 66 of file qjsonarray.h.
References other().
QJsonValue QJsonArray::takeAt | ( | qsizetype | i | ) |
Removes the item at index position i and returns it.
i must be a valid index position in the array (i.e., {0 <= i < size()}).
If you don't use the return value, removeAt() is more efficient.
Definition at line 368 of file qjsonarray.cpp.
References QJsonPrivate::Value::fromTrustedCbor(), i, QJsonValue, and QJsonValue::Undefined.
QVariantList QJsonArray::toVariantList | ( | ) | const |
Converts this object to a QVariantList.
Returns the created map.
Definition at line 234 of file qjsonarray.cpp.
References QCborArray::fromJsonArray(), and QCborArray::toVariantList().
Referenced by deployQmlImports(), QJsonDocument::toVariant(), and QJsonValue::toVariant().
|
friend |
Definition at line 177 of file qjsonarray.h.
|
friend |
Definition at line 128 of file qjsonarray.h.
|
friend |
Definition at line 1060 of file qjsonarray.cpp.
|
friend |
Definition at line 225 of file qjsonarray.h.
|
friend |
Definition at line 224 of file qjsonarray.h.
|
friend |
Definition at line 223 of file qjsonarray.h.
|
friend |
Definition at line 220 of file qjsonarray.h.
|
friend |
Definition at line 221 of file qjsonarray.h.
|
friend |
Definition at line 222 of file qjsonarray.h.
Referenced by operator[]().