QCborArray Class

The QCborArray class is used to hold an array of CBOR elements. More...

Header: #include <QCborArray>
qmake: QT += core
Since: Qt 5.12

This class was introduced in Qt 5.12.

Note: All functions in this class are reentrant.

Public Types

class ConstIterator
class Iterator
typedef const_iterator
typedef const_pointer
typedef const_reference
typedef difference_type
typedef iterator
typedef pointer
typedef reference
typedef size_type
typedef value_type

Public Functions

QCborArray(const QCborArray &other)
QCborArray()
QCborArray &operator=(const QCborArray &other)
~QCborArray()
QCborValue at(qsizetype i) const
void clear()
bool contains(const QCborValue &value) const
void removeAt(qsizetype i)
qsizetype size() const
QJsonArray toJsonArray() const
QVariantList toVariantList() const

Static Public Members

QCborArray fromJsonArray(const QJsonArray &array)
QCborArray fromStringList(const QStringList &list)
QCborArray fromVariantList(const QVariantList &list)

Detailed Description

This class can be used to hold one sequential container in CBOR (an array). CBOR is the Concise Binary Object Representation, a very compact form of binary data encoding that is a superset of JSON. It was created by the IETF Constrained RESTful Environments (CoRE) WG, which has used it in many new RFCs. It is meant to be used alongside the CoAP protocol.

QCborArray is very similar to QVariantList and QJsonArray and its API is almost identical to those two classes. It can also be converted to and from those two, though there may be loss of information in some conversions.

See also QCborValue, QCborMap, QJsonArray, QList, and QVector.

Member Type Documentation

typedef QCborArray::const_iterator

A synonym to QCborArray::ConstIterator.

typedef QCborArray::const_pointer

A typedef to const QCborValue *, for compatibility with generic algorithms.

typedef QCborArray::const_reference

A typedef to const QCborValue &, for compatibility with generic algorithms.

typedef QCborArray::difference_type

A typedef to qsizetype.

typedef QCborArray::iterator

A synonym to QCborArray::Iterator.

typedef QCborArray::pointer

A typedef to QCborValue *, for compatibility with generic algorithms.

typedef QCborArray::reference

A typedef to QCborValue &, for compatibility with generic algorithms.

typedef QCborArray::size_type

A typedef to qsizetype.

typedef QCborArray::value_type

The type of values that can be held in a QCborArray: that is, QCborValue.

Member Function Documentation

QCborArray::QCborArray(const QCborArray &other)

Copies the contents of other into this object.

QCborArray::QCborArray()

Constructs an empty QCborArray.

QCborArray &QCborArray::operator=(const QCborArray &other)

Replaces the contents of this array with that found in other, then returns a reference to this object.

QCborArray::~QCborArray()

Destroys this QCborArray and frees any associated resources.

QCborValue QCborArray::at(qsizetype i) const

Returns the QCborValue element at position i in the array.

If the array is smaller than i elements, this function returns a QCborValue containing an undefined value. For that reason, it is not possible with this function to tell apart the situation where the array is not large enough from the case where the array starts with an undefined value.

See also operator[](), first(), last(), insert(), prepend(), append(), removeAt(), and takeAt().

void QCborArray::clear()

Empties this array.

See also isEmpty().

bool QCborArray::contains(const QCborValue &value) const

Returns true if this array contains an element that is equal to value.

[static] QCborArray QCborArray::fromJsonArray(const QJsonArray &array)

Converts all JSON items found in the array array to CBOR using QCborValue::fromJson(), and returns the CBOR array composed of those elements.

This conversion is lossless, as the CBOR type system is a superset of JSON's. Moreover, the array returned by this function can be converted back to the original array by using toJsonArray().

See also toJsonArray(), toVariantList(), QCborValue::fromJsonValue(), and QCborMap::fromJsonObject().

[static] QCborArray QCborArray::fromStringList(const QStringList &list)

Returns a QCborArray containing all the strings found in the list list.

See also fromVariantList() and fromJsonArray().

[static] QCborArray QCborArray::fromVariantList(const QVariantList &list)

Converts all the items in the list to CBOR using QCborValue::fromVariant() and returns the array composed of those elements.

Conversion from QVariant is not completely lossless. Please see the documentation in QCborValue::fromVariant() for more information.

See also toVariantList(), fromStringList(), fromJsonArray(), and QCborMap::fromVariantMap().

void QCborArray::removeAt(qsizetype i)

Removes the item at position i from the array. The array must have more than i elements before the removal.

See also takeAt(), removeFirst(), removeLast(), at(), operator[](), insert(), prepend(), and append().

qsizetype QCborArray::size() const

Returns the size of this array.

See also isEmpty().

QJsonArray QCborArray::toJsonArray() const

Recursively converts every QCborValue element in this array to JSON using QCborValue::toJsonValue() and returns the corresponding QJsonArray composed of those elements.

Please note that CBOR contains a richer and wider type set than JSON, so some information may be lost in this conversion. For more details on what conversions are applied, see QCborValue::toJsonValue().

See also fromJsonArray(), QCborValue::toJsonValue(), QCborMap::toJsonObject(), and toVariantList().

QVariantList QCborArray::toVariantList() const

Recursively converts each QCborValue in this array using QCborValue::toVariant() and returns the QVariantList composed of the converted items.

Conversion to QVariant is not completely lossless. Please see the documentation in QCborValue::toVariant() for more information.

See also fromVariantList(), fromStringList(), toJsonArray(), QCborValue::toVariant(), and QCborMap::toVariantMap().