QCborArray

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

Inheritance diagram of PySide6.QtCore.QCborArray

New in version 5.12.

Synopsis

Functions

Static functions

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

class PySide6.QtCore.QCborArray

PySide6.QtCore.QCborArray(other)

Parameters

otherPySide6.QtCore.QCborArray

Constructs an empty QCborArray .

Copies the contents of other into this object.

PySide6.QtCore.QCborArray.append(value)
Parameters

valuePySide6.QtCore.QCborValue

PySide6.QtCore.QCborArray.at(i)
Parameters

iqsizetype

Return type

PySide6.QtCore.QCborValue

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.

PySide6.QtCore.QCborArray.clear()

Empties this array.

See also

isEmpty()

PySide6.QtCore.QCborArray.compare(other)
Parameters

otherPySide6.QtCore.QCborArray

Return type

int

Compares this array and other, comparing each element in sequence, and returns an integer that indicates whether this array should be sorted before (if the result is negative) or after other (if the result is positive). If this function returns 0, the two arrays are equal and contain the same elements.

For more information on CBOR sorting order, see compare() .

See also

compare() compare() operator==()

PySide6.QtCore.QCborArray.contains(value)
Parameters

valuePySide6.QtCore.QCborValue

Return type

bool

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

PySide6.QtCore.QCborArray.empty()
Return type

bool

Synonym for isEmpty() . This function is provided for compatibility with generic code that uses the Standard Library API.

Returns true if this array is empty ( size() == 0).

See also

isEmpty() size()

PySide6.QtCore.QCborArray.first()
Return type

PySide6.QtCore.QCborValue

Returns the first QCborValue of this array.

If the array is empty, 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 ends with an undefined value.

static PySide6.QtCore.QCborArray.fromJsonArray(array)
Parameters

arrayPySide6.QtCore.QJsonArray

Return type

PySide6.QtCore.QCborArray

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() .

static PySide6.QtCore.QCborArray.fromStringList(list)
Parameters

list – list of strings

Return type

PySide6.QtCore.QCborArray

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

static PySide6.QtCore.QCborArray.fromVariantList(list)
Parameters

list

Return type

PySide6.QtCore.QCborArray

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

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

PySide6.QtCore.QCborArray.insert(i, value)
Parameters
PySide6.QtCore.QCborArray.isEmpty()
Return type

bool

Returns true if this QCborArray is empty (that is if size() is 0).

See also

size() clear()

PySide6.QtCore.QCborArray.last()
Return type

PySide6.QtCore.QCborValue

Returns the last QCborValue of this array.

If the array is empty, 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 ends with an undefined value.

PySide6.QtCore.QCborArray.__ne__(other)
Parameters

otherPySide6.QtCore.QCborArray

Return type

bool

Compares this array and other, comparing each element in sequence, and returns true if the two arrays’ contents are different, false otherwise.

For more information on CBOR equality in Qt, see, compare() .

See also

compare() operator==() operator==() operator==() operator

PySide6.QtCore.QCborArray.__add__(v)
Parameters

vPySide6.QtCore.QCborValue

Return type

PySide6.QtCore.QCborArray

Returns a new QCborArray containing the same elements as this array, plus v appended as the last element.

See also

operator+=() operator append()

PySide6.QtCore.QCborArray.__iadd__(v)
Parameters

vPySide6.QtCore.QCborValue

Return type

PySide6.QtCore.QCborArray

Appends v to this array and returns a reference to this array.

See also

append() insert() operator+() operator

PySide6.QtCore.QCborArray.__lt__(other)
Parameters

otherPySide6.QtCore.QCborArray

Return type

bool

PySide6.QtCore.QCborArray.__lshift__(v)
Parameters

vPySide6.QtCore.QCborValue

Return type

PySide6.QtCore.QCborArray

PySide6.QtCore.QCborArray.__eq__(other)
Parameters

otherPySide6.QtCore.QCborArray

Return type

bool

Compares this array and other, comparing each element in sequence, and returns true if both arrays contains the same elements, false otherwise.

For more information on CBOR equality in Qt, see, compare() .

See also

compare() operator==() operator==() operator!=() operator

PySide6.QtCore.QCborArray.operator[](i)
Parameters

iqsizetype

Return type

PySide6.QtCore.QCborValue

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 contains an undefined value at position i.

PySide6.QtCore.QCborArray.pop_back()

Synonym for removeLast() . This function is provided for compatibility with generic code that uses the Standard Library API.

Removes the last element of this array. The array must not be empty before the removal

PySide6.QtCore.QCborArray.pop_front()

Synonym for removeFirst() . This function is provided for compatibility with generic code that uses the Standard Library API.

Removes the first element of this array. The array must not be empty before the removal

PySide6.QtCore.QCborArray.prepend(value)
Parameters

valuePySide6.QtCore.QCborValue

PySide6.QtCore.QCborArray.push_back(t)
Parameters

tPySide6.QtCore.QCborValue

Synonym for append() . This function is provided for compatibility with generic code that uses the Standard Library API.

Appends the element t to this array.

PySide6.QtCore.QCborArray.push_front(t)
Parameters

tPySide6.QtCore.QCborValue

Synonym for prepend() . This function is provided for compatibility with generic code that uses the Standard Library API.

Prepends the element t to this array.

PySide6.QtCore.QCborArray.removeAt(i)
Parameters

iqsizetype

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

PySide6.QtCore.QCborArray.removeFirst()

Removes the first item in the array, making the second element become the first. The array must not be empty before this call.

PySide6.QtCore.QCborArray.removeLast()

Removes the last item in the array. The array must not be empty before this call.

PySide6.QtCore.QCborArray.size()
Return type

qsizetype

Returns the size of this array.

See also

isEmpty()

PySide6.QtCore.QCborArray.swap(other)
Parameters

otherPySide6.QtCore.QCborArray

Swaps the contents of this object and other.

PySide6.QtCore.QCborArray.takeAt(i)
Parameters

iqsizetype

Return type

PySide6.QtCore.QCborValue

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

PySide6.QtCore.QCborArray.takeFirst()
Return type

PySide6.QtCore.QCborValue

Removes the first item in the array and returns it, making the second element become the first. The array must not be empty before this call.

PySide6.QtCore.QCborArray.takeLast()
Return type

PySide6.QtCore.QCborValue

Removes the last item in the array and returns it. The array must not be empty before this call.

PySide6.QtCore.QCborArray.toCborValue()
Return type

PySide6.QtCore.QCborValue

Explicitly construcuts a QCborValue object that represents this array. This function is usually not necessary since QCborValue has a constructor for QCborArray , so the conversion is implicit.

Converting QCborArray to QCborValue allows it to be used in any context where QCborValues can be used, including as items in QCborArrays and as keys and mapped types in QCborMap . Converting an array to QCborValue allows access to toCbor() .

See also

QCborValue(const QCborArray &)

PySide6.QtCore.QCborArray.toJsonArray()
Return type

PySide6.QtCore.QJsonArray

Recursively converts every QCborValue element in this array to JSON using 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 toJsonValue() .

PySide6.QtCore.QCborArray.toVariantList()
Return type

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

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