Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QCborValue Class Reference

\inmodule QtCore\reentrant More...

#include <qcborvalue.h>

+ Collaboration diagram for QCborValue:

Public Types

enum  EncodingOption {
  SortKeysInMaps = 0x01 , UseFloat = 0x02 , UseFloat16 = UseFloat | 0x04 , UseIntegers = 0x08 ,
  NoTransformation = 0
}
 This enum is used in the options argument to toCbor(), modifying the behavior of the encoder. More...
 
enum  DiagnosticNotationOption { Compact = 0x00 , LineWrapped = 0x01 , ExtendedFormat = 0x02 }
 This enum is used in the option argument to toDiagnosticNotation(), to modify the output format. More...
 
enum  Type : int {
  Integer = 0x00 , ByteArray = 0x40 , String = 0x60 , Array = 0x80 ,
  Map = 0xa0 , Tag = 0xc0 , SimpleType = 0x100 , False = SimpleType + int(QCborSimpleType::False) ,
  True = SimpleType + int(QCborSimpleType::True) , Null = SimpleType + int(QCborSimpleType::Null) , Undefined = SimpleType + int(QCborSimpleType::Undefined) , Double = 0x202 ,
  DateTime = 0x10000 , Url = 0x10020 , RegularExpression = 0x10023 , Uuid = 0x10025 ,
  Invalid = -1
}
 This enum represents the QCborValue type. More...
 

Public Member Functions

 QCborValue ()
 Creates a QCborValue of the \l {Type}{Undefined} type.
 
 QCborValue (Type t_)
 Creates a QCborValue of type t_.
 
 QCborValue (std::nullptr_t)
 Creates a QCborValue of the \l {Type}{Null} type.
 
 QCborValue (bool b_)
 Creates a QCborValue with boolean value b.
 
 QCborValue (int i)
 
 QCborValue (unsigned u)
 
 QCborValue (qint64 i)
 Creates a QCborValue with integer value i.
 
 QCborValue (double v)
 Creates a QCborValue with floating point value d.
 
 QCborValue (QCborSimpleType st)
 Creates a QCborValue of simple type st.
 
 QCborValue (const QByteArray &ba)
 Creates a QCborValue with byte array value ba.
 
 QCborValue (const QString &s)
 Creates a QCborValue with string value s.
 
 QCborValue (QStringView s)
 Creates a QCborValue with string value s.
 
 QCborValue (QLatin1StringView s)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue with the Latin-1 string viewed by s.
 
QT_ASCII_CAST_WARN QCborValue (const char *s)
 
 QCborValue (const QCborArray &a)
 
 QCborValue (QCborArray &&a)
 Creates a QCborValue with the array a.
 
 QCborValue (const QCborMap &m)
 
 QCborValue (QCborMap &&m)
 Creates a QCborValue with the map m.
 
 QCborValue (QCborTag tag, const QCborValue &taggedValue=QCborValue())
 
 QCborValue (QCborKnownTags t_, const QCborValue &tv=QCborValue())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue for the extended type represented by the tag value tag, tagging value taggedValue.
 
 QCborValue (const QDateTime &dt)
 Creates a QCborValue object of the date/time extended type and containing the value represented by dt.
 
 QCborValue (const QUrl &url)
 Creates a QCborValue object of the URL extended type and containing the value represented by url.
 
 QCborValue (const QUuid &uuid)
 Creates a QCborValue object of the UUID extended type and containing the value represented by uuid.
 
 ~QCborValue ()
 Disposes of the current QCborValue object and frees any associated resources.
 
 QCborValue (const void *)=delete
 
 QCborValue (const QCborValue &other) noexcept
 Copies the contents of other into this object.
 
 QCborValue (QCborValue &&other) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one.
 
QCborValueoperator= (const QCborValue &other) noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one.
 
void swap (QCborValue &other) noexcept
 Swaps the contents of this QCborValue object and other.
 
Type type () const
 Returns the type of this QCborValue.
 
bool isInteger () const
 Returns true if this QCborValue is of the integer type.
 
bool isByteArray () const
 Returns true if this QCborValue is of the byte array type.
 
bool isString () const
 Returns true if this QCborValue is of the string type.
 
bool isArray () const
 Returns true if this QCborValue is of the array type.
 
bool isMap () const
 Returns true if this QCborValue is of the map type.
 
bool isTag () const
 Returns true if this QCborValue is of the tag type.
 
bool isFalse () const
 Returns true if this QCborValue is a boolean with false value.
 
bool isTrue () const
 Returns true if this QCborValue is a boolean with true value.
 
bool isBool () const
 Returns true if this QCborValue is a boolean.
 
bool isNull () const
 Returns true if this QCborValue is of the null type.
 
bool isUndefined () const
 Returns true if this QCborValue is of the undefined type.
 
bool isDouble () const
 Returns true if this QCborValue is of the floating-point type.
 
bool isDateTime () const
 Returns true if this QCborValue is of the date/time type.
 
bool isUrl () const
 Returns true if this QCborValue is of the URL type.
 
bool isRegularExpression () const
 Returns true if this QCborValue contains a regular expression's pattern.
 
bool isUuid () const
 Returns true if this QCborValue contains a UUID.
 
bool isInvalid () const
 Returns true if this QCborValue is not of any valid type.
 
bool isContainer () const
 This convenience function returns true if the QCborValue is either an array or a map.
 
bool isSimpleType () const
 Returns true if this QCborValue is of one of the CBOR simple types.
 
bool isSimpleType (QCborSimpleType st) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if this QCborValue is of a simple type and toSimpleType() would return st, false otherwise.
 
QCborSimpleType toSimpleType (QCborSimpleType defaultValue=QCborSimpleType::Undefined) const
 Returns the simple type this QCborValue is of, if it is a simple type.
 
qint64 toInteger (qint64 defaultValue=0) const
 Returns the integer value stored in this QCborValue, if it is of the integer type.
 
bool toBool (bool defaultValue=false) const
 Returns the boolean value stored in this QCborValue, if it is of a boolean type.
 
double toDouble (double defaultValue=0) const
 Returns the floating point value stored in this QCborValue, if it is of the Double type.
 
QCborTag tag (QCborTag defaultValue=QCborTag(-1)) const
 Returns the tag of this extended QCborValue object, if it is of the tag type, defaultValue otherwise.
 
QCborValue taggedValue (const QCborValue &defaultValue=QCborValue()) const
 Returns the tagged value of this extended QCborValue object, if it is of the tag type, defaultValue otherwise.
 
QByteArray toByteArray (const QByteArray &defaultValue={}) const
 Returns the byte array value stored in this QCborValue, if it is of the byte array type.
 
QString toString (const QString &defaultValue={}) const
 Returns the string value stored in this QCborValue, if it is of the string type.
 
QDateTime toDateTime (const QDateTime &defaultValue={}) const
 Returns the date/time value stored in this QCborValue, if it is of the date/time extended type.
 
QUrl toUrl (const QUrl &defaultValue={}) const
 Returns the URL value stored in this QCborValue, if it is of the URL extended type.
 
QUuid toUuid (const QUuid &defaultValue={}) const
 Returns the UUID value stored in this QCborValue, if it is of the UUID extended type.
 
QCborArray toArray () const
 
QCborArray toArray (const QCborArray &defaultValue) const
 Returns the array value stored in this QCborValue, if it is of the array type.
 
QCborMap toMap () const
 
QCborMap toMap (const QCborMap &defaultValue) const
 Returns the map value stored in this QCborValue, if it is of the map type.
 
const QCborValue operator[] (const QString &key) const
 If this QCborValue is a QCborMap, searches elements for the value whose key matches key.
 
const QCborValue operator[] (QLatin1StringView key) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key.
 
const QCborValue operator[] (qint64 key) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key.
 
QCborValueRef operator[] (qint64 key)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map or array, with the given key.
 
QCborValueRef operator[] (QLatin1StringView key)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key.
 
QCborValueRef operator[] (const QString &key)
 Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key.
 
int compare (const QCborValue &other) const
 Compares this value and other, and returns an integer that indicates whether this value should be sorted prior to (if the result is negative) or after other (if the result is positive).
 
QVariant toVariant () const
 Converts this value to a native Qt type and returns the corresponding QVariant.
 
QJsonValue toJsonValue () const
 Converts this QCborValue object to an equivalent representation in JSON and returns it as a QJsonValue.
 
QString toDiagnosticNotation (DiagnosticNotationOptions opts=Compact) const
 Creates the diagnostic notation equivalent of this CBOR object and returns it.
 

Static Public Member Functions

static QCborValue fromVariant (const QVariant &variant)
 Converts the QVariant variant into QCborValue and returns it.
 
static QCborValue fromJsonValue (const QJsonValue &v)
 Converts the JSON value contained in v into its corresponding CBOR value and returns it.
 

Friends

class QCborArray
 
class QCborMap
 
class QCborValueConstRef
 
class QCborValueRef
 
class QCborContainerPrivate
 
class QJsonPrivate::Value
 
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool comparesEqual (const QCborValue &lhs, const QCborValue &rhs) noexcept
 
Qt::strong_ordering compareThreeWay (const QCborValue &lhs, const QCborValue &rhs) noexcept
 

Detailed Description

\inmodule QtCore

\reentrant

Since
5.12

The QCborValue class encapsulates a value in CBOR.

\compares strong

This class can be used to hold one of the many types available in CBOR. 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 \l{RFC 7252}{CoAP protocol}.

CBOR has three groups of built-in types:

\list

  • Basic types: integers, floating point (double), boolean, null, etc.
  • String-like types: strings and byte arrays
  • Containers: arrays and maps \endlist

Additionally, CBOR supports a form of type extensibility by associating a "tag" to one of the above types to convey more information. For example, a UUID is represented by a tag and a byte array containing the 16 bytes of the UUID content. QCborValue supports creating and decoding several of those extended types directly with Qt classes (like QUuid).

For the complete list, see \l QCborValue::Type. The type of a QCborValue can be queried using type() or one of the "isXxxx" functions.

Definition at line 46 of file qcborvalue.h.

Member Enumeration Documentation

◆ DiagnosticNotationOption

This enum is used in the option argument to toDiagnosticNotation(), to modify the output format.

\value Compact Does not use any line-breaks, producing a compact representation. \value LineWrapped Uses line-breaks, one QCborValue per line. \value ExtendedFormat Uses some different options to represent values, not found in RFC 7049. Those options are subject to change.

Currently, ExtendedFormat will change how byte arrays are represented. Without it, they are always hex-encoded and without spaces. With it, QCborValue::toCbor() will either use hex with spaces, base64 or base64url encoding, depending on the context.

See also
toDiagnosticNotation()
Enumerator
Compact 
LineWrapped 
ExtendedFormat 

Definition at line 62 of file qcborvalue.h.

◆ EncodingOption

This enum is used in the options argument to toCbor(), modifying the behavior of the encoder.

\omitvalue SortKeysInMaps \value NoTransformation (Default) Performs no transformations. \value UseFloat Tells the encoder to use IEEE 754 single-precision floating point (that is, float) whenever possible. \value UseFloat16 Tells the encoder to use IEEE 754 half-precision floating point (that is, qfloat16), whenever possible. Implies UseFloat. \value UseIntegers Tells the encoder to use integers whenever a value of type \l {Type}{Double} contains an integer.

The use of UseFloat16 is required to encode the stream in Canonical Format, but is not otherwise necessary.

See also
toCbor()
Enumerator
SortKeysInMaps 
UseFloat 
UseFloat16 
UseIntegers 
NoTransformation 

Definition at line 50 of file qcborvalue.h.

◆ Type

enum QCborValue::Type : int

This enum represents the QCborValue type.

It is returned by the type() function.

The CBOR built-in types are:

\value Integer qint64: An integer value \value ByteArray \l QByteArray: a byte array ("byte string") \value String \l QString: a Unicode string ("text string") \value Array \l QCborArray: an array of QCborValues \value Map \l QCborMap: an associative container of QCborValues \value SimpleType \l QCborSimpleType: one of several simple types/values \value False bool: the simple type for value false \value True bool: the simple type for value true \value Null std::nullptr_t: the simple type for the null value \value Undefined (no type) the simple type for the undefined value \value Double double: a double-precision floating point \value Invalid Not a valid value, this usually indicates a CBOR decoding error

Additionally, QCborValue can represent extended types:

\value Tag An unknown or unrecognized extended type, represented by its tag (a \l QCborTag) and the tagged value (a QCborValue) \value DateTime \l QDateTime: a date and time stamp \value Url \l QUrl: a URL or URI \value RegularExpression \l QRegularExpression: the pattern of a regular expression \value Uuid \l QUuid: a UUID

See also
type()
Enumerator
Integer 
ByteArray 
String 
Array 
Map 
Tag 
SimpleType 
False 
True 
Null 
Undefined 
Double 
DateTime 
Url 
RegularExpression 
Uuid 
Invalid 

Definition at line 70 of file qcborvalue.h.

Constructor & Destructor Documentation

◆ QCborValue() [1/26]

QCborValue::QCborValue ( )
inline

Creates a QCborValue of the \l {Type}{Undefined} type.

CBOR undefined values are used to indicate missing information, usually as a result of a previous operation that did not complete as expected. They are also used by the QCborArray and QCborMap API to indicate the searched item was not found.

Undefined values are represented by the \l {QCborSimpleType}{Undefined simple type}. Because of that, QCborValues with undefined values will also return true for isSimpleType() and {isSimpleType(QCborSimpleType::Undefined)}.

Undefined values are different from null values.

QCborValue objects with undefined values are also different from invalid QCborValue objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.

See also
isUndefined(), isNull(), isSimpleType()

Definition at line 97 of file qcborvalue.h.

◆ QCborValue() [2/26]

QCborValue::QCborValue ( Type t_)
inline

Creates a QCborValue of type t_.

The value associated with such a type (if any) will be default constructed.

See also
type()

Definition at line 98 of file qcborvalue.h.

◆ QCborValue() [3/26]

QCborValue::QCborValue ( std::nullptr_t )
inline

Creates a QCborValue of the \l {Type}{Null} type.

CBOR null values are used to indicate optional values that were not provided. They are distinct from undefined values, in that null values are usually not the result of an earlier error or problem.

See also
isNull(), isUndefined(), isSimpleType()

Definition at line 99 of file qcborvalue.h.

◆ QCborValue() [4/26]

QCborValue::QCborValue ( bool b)
inline

Creates a QCborValue with boolean value b.

The value can later be retrieved using toBool().

Internally, CBOR booleans are represented by a pair of types, one for true and one for false. For that reason, boolean QCborValues will return true for isSimpleType() and one of {isSimpleType(QCborSimpleType::False)} or {isSimpleType(QCborSimpleType::True)}.

See also
toBool(), isBool(), isTrue(), isFalse(), isSimpleType()

Definition at line 100 of file qcborvalue.h.

◆ QCborValue() [5/26]

QCborValue::QCborValue ( int i)
inline

Definition at line 102 of file qcborvalue.h.

◆ QCborValue() [6/26]

QCborValue::QCborValue ( unsigned u)
inline

Definition at line 103 of file qcborvalue.h.

◆ QCborValue() [7/26]

QCborValue::QCborValue ( qint64 i)
inline

Creates a QCborValue with integer value i.

The value can later be retrieved using toInteger().

CBOR integer values are distinct from floating point values. Therefore, QCborValue objects with integers will compare differently to QCborValue objects containing floating-point, even if the values contained in the objects are equivalent.

See also
toInteger(), isInteger(), isDouble()

Definition at line 105 of file qcborvalue.h.

◆ QCborValue() [8/26]

QCborValue::QCborValue ( double d)
inline

Creates a QCborValue with floating point value d.

The value can later be retrieved using toDouble().

CBOR floating point values are distinct from integer values. Therefore, QCborValue objects with integers will compare differently to QCborValue objects containing floating-point, even if the values contained in the objects are equivalent.

See also
toDouble(), isDouble(), isInteger()

Definition at line 106 of file qcborvalue.h.

◆ QCborValue() [9/26]

QCborValue::QCborValue ( QCborSimpleType st)
inline

Creates a QCborValue of simple type st.

The type can later be retrieved using toSimpleType() as well as isSimpleType(st).

CBOR simple types are types that do not have any associated value, like C++'s {std::nullptr_t} type, whose only possible value is \nullptr.

If st is {QCborSimpleType::Null}, the resulting QCborValue will be of the \l{Type}{Null} type and similarly for {QCborSimpleType::Undefined}. If st is {QCborSimpleType::False} or {QCborSimpleType::True}, the created QCborValue will be a boolean containing a value of false or true, respectively.

This function can be used with simple types not defined in the API. For example, to create a QCborValue with simple type 12, one could write:

Simple types should not be used until a specification for them has been published, since other implementations may not support them properly. Simple type values 24 to 31 are reserved and must not be used.

isSimpleType(), isNull(), isUndefined(), isTrue(), isFalse()

Definition at line 107 of file qcborvalue.h.

◆ QCborValue() [10/26]

QCborValue::QCborValue ( const QByteArray & ba)

Creates a QCborValue with byte array value ba.

The value can later be retrieved using toByteArray().

See also
toByteArray(), isByteArray(), isString()

Definition at line 1930 of file qcborvalue.cpp.

References QCborContainerPrivate::appendByteData(), ba, QByteArray::constData(), QSharedData::ref, QByteArray::size(), and QBasicAtomicInteger< T >::storeRelaxed().

+ Here is the call graph for this function:

◆ QCborValue() [11/26]

QCborValue::QCborValue ( const QString & s)

Creates a QCborValue with string value s.

The value can later be retrieved using toString().

See also
toString(), isString(), isByteArray()

Definition at line 1943 of file qcborvalue.cpp.

◆ QCborValue() [12/26]

QCborValue::QCborValue ( QStringView s)

Creates a QCborValue with string value s.

The value can later be retrieved using toString().

See also
toString(), isString(), isByteArray()

Definition at line 1951 of file qcborvalue.cpp.

References QCborContainerPrivate::append(), QSharedData::ref, and QBasicAtomicInteger< T >::storeRelaxed().

+ Here is the call graph for this function:

◆ QCborValue() [13/26]

QCborValue::QCborValue ( QLatin1StringView s)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue with the Latin-1 string viewed by s.

The value can later be retrieved using toString().

See also
toString(), isString(), isByteArray()

Definition at line 1966 of file qcborvalue.cpp.

References QCborContainerPrivate::append(), QSharedData::ref, and QBasicAtomicInteger< T >::storeRelaxed().

+ Here is the call graph for this function:

◆ QCborValue() [14/26]

QT_ASCII_CAST_WARN QCborValue::QCborValue ( const char * s)
inline

Definition at line 114 of file qcborvalue.h.

◆ QCborValue() [15/26]

QCborValue::QCborValue ( const QCborArray & a)

Definition at line 1982 of file qcborvalue.cpp.

References QBasicAtomicInteger< T >::ref(), and QSharedData::ref.

+ Here is the call graph for this function:

◆ QCborValue() [16/26]

QCborValue::QCborValue ( QCborArray && a)
inline

Creates a QCborValue with the array a.

The array can later be retrieved using toArray().

See also
toArray(), isArray(), isMap()

Definition at line 359 of file qcborarray.h.

◆ QCborValue() [17/26]

QCborValue::QCborValue ( const QCborMap & m)

Definition at line 1998 of file qcborvalue.cpp.

References QBasicAtomicInteger< T >::ref(), and QSharedData::ref.

+ Here is the call graph for this function:

◆ QCborValue() [18/26]

QCborValue::QCborValue ( QCborMap && m)
inline

Creates a QCborValue with the map m.

The map can later be retrieved using toMap().

See also
toMap(), isMap(), isArray()

Definition at line 430 of file qcbormap.h.

◆ QCborValue() [19/26]

QCborValue::QCborValue ( QCborTag tag,
const QCborValue & taggedValue = QCborValue() )

Definition at line 2015 of file qcborvalue.cpp.

References QCborContainerPrivate::append(), convertToExtendedType(), QSharedData::ref, QBasicAtomicInteger< T >::storeRelaxed(), and tag.

+ Here is the call graph for this function:

◆ QCborValue() [20/26]

QCborValue::QCborValue ( QCborKnownTags tag,
const QCborValue & tv = QCborValue() )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a QCborValue for the extended type represented by the tag value tag, tagging value taggedValue.

Creates a QCborValue for the extended type represented by the tag value tag, tagging value tv.

The tag can later be retrieved using tag() and the tagged value using taggedValue().

See also
isTag(), tag(), taggedValue(), QCborKnownTags

Definition at line 121 of file qcborvalue.h.

◆ QCborValue() [21/26]

QCborValue::QCborValue ( const QDateTime & dt)
explicit

Creates a QCborValue object of the date/time extended type and containing the value represented by dt.

The value can later be retrieved using toDateTime().

The CBOR date/time types are extension types using tags: either a string (in ISO date format) tagged as a \l{QCborKnownTags}{DateTime} or a number (of seconds since the start of 1970, UTC) tagged as a \l{QCborKnownTags}{UnixTime_t}. When parsing CBOR streams, QCborValue will convert \l{QCborKnownTags}{UnixTime_t} to the string-based type.

See also
toDateTime(), isDateTime(), taggedValue()

Definition at line 2047 of file qcborvalue.cpp.

References DateTime, QCborContainerPrivate::elements, and String.

◆ QCborValue() [22/26]

QCborValue::QCborValue ( const QUrl & url)
explicit

Creates a QCborValue object of the URL extended type and containing the value represented by url.

The value can later be retrieved using toUrl().

The CBOR URL type is an extended type represented by a string tagged as an \l{QCborKnownTags}{Url}.

See also
toUrl(), isUrl(), taggedValue()

Definition at line 2065 of file qcborvalue.cpp.

References QCborContainerPrivate::elements, String, and Url.

◆ QCborValue() [23/26]

QCborValue::QCborValue ( const QUuid & uuid)
explicit

Creates a QCborValue object of the UUID extended type and containing the value represented by uuid.

The value can later be retrieved using toUuid().

The CBOR UUID type is an extended type represented by a byte array tagged as an \l{QCborKnownTags}{Uuid}.

See also
toUuid(), isUuid(), taggedValue()

Definition at line 2104 of file qcborvalue.cpp.

References Uuid.

◆ ~QCborValue()

QCborValue::~QCborValue ( )
inline

Disposes of the current QCborValue object and frees any associated resources.

Definition at line 134 of file qcborvalue.h.

◆ QCborValue() [24/26]

QCborValue::QCborValue ( const void * )
delete

◆ QCborValue() [25/26]

QCborValue::QCborValue ( const QCborValue & other)
noexcept

Copies the contents of other into this object.

Definition at line 2027 of file qcborvalue.cpp.

◆ QCborValue() [26/26]

QCborValue::QCborValue ( QCborValue && other)
inlinenoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one.

Definition at line 140 of file qcborvalue.h.

Member Function Documentation

◆ compare()

int QCborValue::compare ( const QCborValue & other) const

Compares this value and other, and returns an integer that indicates whether this value should be sorted prior to (if the result is negative) or after other (if the result is positive).

If this function returns 0, the two values are equal and hold the same contents.

If each QCborValue contains an array or map, the comparison is recursive to elements contained in them.

Definition at line 1492 of file qcborvalue.cpp.

References compareElementRecursive(), QCborContainerPrivate::elementFromValue(), and other().

+ Here is the call graph for this function:

◆ fromJsonValue()

QCborValue QCborValue::fromJsonValue ( const QJsonValue & v)
static

Converts the JSON value contained in v into its corresponding CBOR value and returns it.

There is no data loss in converting from JSON to CBOR, as the CBOR type set is richer than JSON's. Additionally, values converted to CBOR using this function can be converted back to JSON using toJsonValue() with no data loss.

The following table lists the mapping of JSON types to CBOR types:

\table \header

  • JSON Type
  • CBOR Type \row
  • Bool
  • Bool \row
  • Number
  • Integer (if the number has no fraction and is in the \l qint64 range) or Double \row
  • String
  • String \row
  • Array
  • Array \row
  • Object
  • Map \row
  • Null
  • Null \endtable

\l QJsonValue can also be undefined, indicating a previous operation that failed to complete (for example, searching for a key not present in an object). Undefined values are not JSON types and may not appear in JSON arrays and objects, but this function does return the QCborValue undefined value if the corresponding QJsonValue is undefined.

See also
toJsonValue(), fromVariant(), QCborArray::fromJsonArray(), QCborMap::fromJsonObject()

Definition at line 614 of file qjsoncbor.cpp.

References QJsonValue::Array, QJsonValue::Bool, QJsonValue::Double, QCborArray::fromJsonArray(), QCborMap::fromJsonObject(), QJsonValue::Null, QJsonValue::Object, QCborValue(), QJsonValue::String, and QJsonValue::Undefined.

Referenced by fromJson(), QJsonArray::insert(), QJsonArray::replace(), QJsonDocument::setArray(), and QJsonDocument::setObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromVariant()

QCborValue QCborValue::fromVariant ( const QVariant & variant)
static

Converts the QVariant variant into QCborValue and returns it.

QVariants may contain a large list of different meta types, many of which have no corresponding representation in CBOR. That includes all user-defined meta types. When preparing transmission using CBOR, it is suggested to encode carefully each value to prevent loss of representation.

The following table lists the conversion this function will apply:

\table \header

If QVariant::isNull() returns true, a null QCborValue is returned or inserted into the list or object, regardless of the type carried by QVariant. Note the behavior change in Qt 6.0 affecting QVariant::isNull() also affects this function.

For other types not listed above, a conversion to string will be attempted, usually but not always by calling QVariant::toString(). If the conversion fails the value is replaced by an Undefined CBOR value. Note that QVariant::toString() is also lossy for the majority of types.

Please note that the conversions via QVariant::toString() are subject to change at any time. Both QVariant and QCborValue may be extended in the future to support more types, which will result in a change in how this function performs conversions.

See also
toVariant(), fromJsonValue(), QCborArray::toVariantList(), QCborMap::toVariantMap(), QJsonValue::fromVariant()

Definition at line 707 of file qjsoncbor.cpp.

References QJsonDocument::array(), QCborArray::fromJsonArray(), QCborMap::fromJsonObject(), QCborArray::fromStringList(), QCborMap::fromVariantHash(), QCborArray::fromVariantList(), QCborMap::fromVariantMap(), QMetaType::id(), QJsonDocument::isArray(), QVariant::isNull(), QVariant::metaType(), QJsonDocument::object(), Q_FALLTHROUGH, QCborValue(), QVariant::toBool(), QVariant::toByteArray(), QVariant::toDateTime(), QVariant::toDouble(), QVariant::toHash(), QVariant::toJsonArray(), QVariant::toJsonDocument(), QVariant::toJsonObject(), QVariant::toJsonValue(), QVariant::toList(), QVariant::toLongLong(), QVariant::toMap(), QVariant::toString(), QVariant::toStringList(), QVariant::toULongLong(), QVariant::toUrl(), QVariant::toUuid(), QMetaType::UnknownType, and variant.

Referenced by appendVariant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isArray()

bool QCborValue::isArray ( ) const
inline

Returns true if this QCborValue is of the array type.

The array value can be retrieved using toArray().

See also
type(), toArray()

Definition at line 158 of file qcborvalue.h.

Referenced by Interface::Interface(), operator[](), MetaTypesJsonProcessor::processTypes(), and toArray().

+ Here is the caller graph for this function:

◆ isBool()

bool QCborValue::isBool ( ) const
inline

Returns true if this QCborValue is a boolean.

The value can be retrieved using toBool().

See also
type(), toBool(), isTrue(), isFalse()

Definition at line 163 of file qcborvalue.h.

◆ isByteArray()

bool QCborValue::isByteArray ( ) const
inline

Returns true if this QCborValue is of the byte array type.

The byte array value can be retrieved using toByteArray().

See also
type(), toByteArray()

Definition at line 156 of file qcborvalue.h.

Referenced by toByteArray().

+ Here is the caller graph for this function:

◆ isContainer()

bool QCborValue::isContainer ( ) const
inline

This convenience function returns true if the QCborValue is either an array or a map.

See also
isArray(), isMap()

Definition at line 172 of file qcborvalue.h.

◆ isDateTime()

bool QCborValue::isDateTime ( ) const
inline

Returns true if this QCborValue is of the date/time type.

The value can be retrieved using toDateTime(). Date/times are extended types that use the tag \l{QCborKnownTags}{DateTime}.

Additionally, when decoding from a CBOR stream, QCborValue will interpret tags of value \l{QCborKnownTags}{UnixTime_t} and convert them to the equivalent date/time.

See also
type(), toDateTime()

Definition at line 167 of file qcborvalue.h.

Referenced by toDateTime().

+ Here is the caller graph for this function:

◆ isDouble()

bool QCborValue::isDouble ( ) const
inline

Returns true if this QCborValue is of the floating-point type.

The value can be retrieved using toDouble().

See also
type(), toDouble()

Definition at line 166 of file qcborvalue.h.

◆ isFalse()

bool QCborValue::isFalse ( ) const
inline

Returns true if this QCborValue is a boolean with false value.

This function exists because, internally, CBOR booleans are stored as two separate types, one for true and one for false.

See also
type(), isBool(), isTrue(), toBool()

Definition at line 161 of file qcborvalue.h.

References False.

◆ isInteger()

bool QCborValue::isInteger ( ) const
inline

Returns true if this QCborValue is of the integer type.

The integer value can be retrieved using toInteger().

See also
type(), toInteger()

Definition at line 155 of file qcborvalue.h.

◆ isInvalid()

bool QCborValue::isInvalid ( ) const
inline

Returns true if this QCborValue is not of any valid type.

Invalid QCborValues are distinct from those with undefined values and they usually represent a decoding error.

See also
isUndefined(), isNull()

Definition at line 171 of file qcborvalue.h.

References Invalid.

◆ isMap()

bool QCborValue::isMap ( ) const
inline

Returns true if this QCborValue is of the map type.

The map value can be retrieved using toMap().

See also
type(), toMap()

Definition at line 159 of file qcborvalue.h.

Referenced by MetaTypesJsonProcessor::processTypes(), and toMap().

+ Here is the caller graph for this function:

◆ isNull()

bool QCborValue::isNull ( ) const
inline

Returns true if this QCborValue is of the null type.

CBOR null values are used to indicate optional values that were not provided. They are distinct from undefined values, in that null values are usually not the result of an earlier error or problem.

Null values are distinct from undefined values and from invalid QCborValue objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.

See also
type(), isUndefined(), isInvalid()

Definition at line 164 of file qcborvalue.h.

References Null.

◆ isRegularExpression()

bool QCborValue::isRegularExpression ( ) const
inline

Returns true if this QCborValue contains a regular expression's pattern.

The pattern can be retrieved using toRegularExpression().

See also
type(), toRegularExpression()

Definition at line 169 of file qcborvalue.h.

References RegularExpression.

◆ isSimpleType() [1/2]

bool QCborValue::isSimpleType ( ) const
inline

Returns true if this QCborValue is of one of the CBOR simple types.

The type itself can later be retrieved using type(), even for types that don't have an enumeration in the API. They can also be checked with the \l{isSimpleType(QCborSimpleType)} overload.

See also
QCborSimpleType, isSimpleType(QCborSimpleType), toSimpleType()

Definition at line 174 of file qcborvalue.h.

◆ isSimpleType() [2/2]

bool QCborValue::isSimpleType ( QCborSimpleType st) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if this QCborValue is of a simple type and toSimpleType() would return st, false otherwise.

This function can be used to check for any CBOR simple type, even those for which there is no enumeration in the API. For example, for the simple type of value 12, you could write:

See also
QCborValue::QCborValue(QCborSimpleType), isSimpleType(), isFalse(), isTrue(), isNull, isUndefined(), toSimpleType()

Definition at line 178 of file qcborvalue.h.

◆ isString()

bool QCborValue::isString ( ) const
inline

Returns true if this QCborValue is of the string type.

The string value can be retrieved using toString().

See also
type(), toString()

Definition at line 157 of file qcborvalue.h.

Referenced by toString().

+ Here is the caller graph for this function:

◆ isTag()

bool QCborValue::isTag ( ) const
inline

Returns true if this QCborValue is of the tag type.

The tag value can be retrieved using tag() and the tagged value using taggedValue().

This function also returns true for extended types that the API recognizes. For code that handles extended types directly before the Qt API is updated to support them, it is possible to recreate the tag + tagged value pair by using taggedValue().

See also
type(), tag(), taggedValue(), taggedValue()

Definition at line 160 of file qcborvalue.h.

Referenced by tag(), and taggedValue().

+ Here is the caller graph for this function:

◆ isTrue()

bool QCborValue::isTrue ( ) const
inline

Returns true if this QCborValue is a boolean with true value.

This function exists because, internally, CBOR booleans are stored as two separate types, one for false and one for true.

See also
type(), isBool(), isFalse(), toBool()

Definition at line 162 of file qcborvalue.h.

References True.

◆ isUndefined()

bool QCborValue::isUndefined ( ) const
inline

Returns true if this QCborValue is of the undefined type.

CBOR undefined values are used to indicate missing information, usually as a result of a previous operation that did not complete as expected. They are also used by the QCborArray and QCborMap API to indicate the searched item was not found.

Undefined values are distinct from null values.

QCborValue objects with undefined values are also different from invalid QCborValue objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.

See also
type(), isNull(), isInvalid()

Definition at line 165 of file qcborvalue.h.

References Undefined.

◆ isUrl()

bool QCborValue::isUrl ( ) const
inline

Returns true if this QCborValue is of the URL type.

The URL value can be retrieved using toUrl().

See also
type(), toUrl()

Definition at line 168 of file qcborvalue.h.

References Url.

Referenced by toUrl().

+ Here is the caller graph for this function:

◆ isUuid()

bool QCborValue::isUuid ( ) const
inline

Returns true if this QCborValue contains a UUID.

The value can be retrieved using toUuid().

See also
type(), toUuid()

Definition at line 170 of file qcborvalue.h.

References Uuid.

Referenced by toUuid().

+ Here is the caller graph for this function:

◆ operator=()

QCborValue & QCborValue::operator= ( const QCborValue & other)
noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the contents of the other QCborValue object into this one and frees the resources of this one.

Replaces the contents of this QCborObject with a copy of other.

Returns a reference to this object.

Definition at line 2121 of file qcborvalue.cpp.

References assignContainer(), and other().

+ Here is the call graph for this function:

◆ operator[]() [1/6]

QCborValueRef QCborValue::operator[] ( const QString & key)

Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key.

When this QCborValue is a QCborMap, this function is equivalent to the matching operator[] on that map.

Before returning the reference: if this QCborValue was an array, it is first converted to a map (so that {map[i]} is {array[i]} for each index, i, with valid {array[i]}); otherwise, if it was not a map it will be over-written with an empty map.

See also
operator[](qint64), QCborMap::operator[], QCborMap::value(), QCborMap::find()

Definition at line 2534 of file qcborvalue.cpp.

References QCborContainerPrivate::findOrAddMapKey(), and qToStringViewIgnoringNull().

+ Here is the call graph for this function:

◆ operator[]() [2/6]

const QCborValue QCborValue::operator[] ( const QString & key) const

If this QCborValue is a QCborMap, searches elements for the value whose key matches key.

If there's no key matching key in the map or if this QCborValue object is not a map, returns the undefined value.

This function is equivalent to:

See also
operator[](qint64), QCborMap::operator[], QCborMap::value(), QCborMap::find()

Definition at line 2384 of file qcborvalue.cpp.

References QCborContainerPrivate::findCborMapKey(), and qToStringViewIgnoringNull().

+ Here is the call graph for this function:

◆ operator[]() [3/6]

QCborValueRef QCborValue::operator[] ( qint64 key)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map or array, with the given key.

When this QCborValue is a QCborMap or, for 0 <= key < 0x10000, a QCborArray, this function is equivalent to the matching operator[] on that map or array.

Before returning the reference: if this QCborValue was an array but the key is out of range, the array is first converted to a map (so that {map[i]} is {array[i]} for each index, i, with valid {array[i]}); otherwise, if it was not a map it will be over-written with an empty map.

See also
operator[], QCborMap::operator[], QCborMap::value(), QCborMap::find(), QCborArray::operator[], QCborArray::at()

Definition at line 2575 of file qcborvalue.cpp.

References QCborContainerPrivate::findOrAddMapKey(), maybeGrow(), and shouldArrayRemainArray().

+ Here is the call graph for this function:

◆ operator[]() [4/6]

const QCborValue QCborValue::operator[] ( qint64 key) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key.

If this is a QCborArray, returns the element whose index is key. If there's no matching value in the array or map, or if this QCborValue object is not an array or map, returns the undefined value.

See also
operator[], QCborMap::operator[], QCborMap::value(), QCborMap::find(), QCborArray::operator[], QCborArray::at()

Definition at line 2419 of file qcborvalue.cpp.

References QCborContainerPrivate::elements, QCborContainerPrivate::findCborMapKey(), isArray(), QList< T >::size(), and QCborContainerPrivate::valueAt().

+ Here is the call graph for this function:

◆ operator[]() [5/6]

QCborValueRef QCborValue::operator[] ( QLatin1StringView key)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key.

When this QCborValue is a QCborMap, this function is equivalent to the matching operator[] on that map.

Before returning the reference: if this QCborValue was an array, it is first converted to a map (so that {map[i]} is {array[i]} for each index, i, with valid {array[i]}); otherwise, if it was not a map it will be over-written with an empty map.

See also
operator[](qint64), QCborMap::operator[], QCborMap::value(), QCborMap::find()

Definition at line 2554 of file qcborvalue.cpp.

References QCborContainerPrivate::findOrAddMapKey().

+ Here is the call graph for this function:

◆ operator[]() [6/6]

const QCborValue QCborValue::operator[] ( QLatin1StringView key) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If this QCborValue is a QCborMap, searches elements for the value whose key matches key.

If there's no key matching key in the map or if this QCborValue object is not a map, returns the undefined value.

This function is equivalent to:

See also
operator[](qint64), QCborMap::operator[], QCborMap::value(), QCborMap::find()

Definition at line 2403 of file qcborvalue.cpp.

References QCborContainerPrivate::findCborMapKey().

+ Here is the call graph for this function:

◆ swap()

void QCborValue::swap ( QCborValue & other)
inlinenoexcept

Swaps the contents of this QCborValue object and other.

Definition at line 147 of file qcborvalue.h.

References other(), and qt_ptr_swap().

+ Here is the call graph for this function:

◆ tag()

QCborTag QCborValue::tag ( QCborTag defaultValue = QCborTag(-1)) const

Returns the tag of this extended QCborValue object, if it is of the tag type, defaultValue otherwise.

CBOR represents extended types by associating a number (the tag) with a stored representation. This function returns that number. To retrieve the representation, use taggedValue().

See also
isTag(), taggedValue(), isDateTime(), isUrl(), isRegularExpression(), isUuid()

Definition at line 2139 of file qcborvalue.cpp.

References QList< T >::at(), QCborContainerPrivate::elements, isTag(), QList< T >::size(), and QtCbor::Element::value.

+ Here is the call graph for this function:

◆ taggedValue()

QCborValue QCborValue::taggedValue ( const QCborValue & defaultValue = QCborValue()) const

Returns the tagged value of this extended QCborValue object, if it is of the tag type, defaultValue otherwise.

CBOR represents extended types by associating a number (the tag) with a stored representation. This function returns that representation. To retrieve the tag, use tag().

See also
isTag(), tag(), isDateTime(), isUrl(), isRegularExpression(), isUuid()

Definition at line 2155 of file qcborvalue.cpp.

References QCborContainerPrivate::elements, isTag(), QList< T >::size(), and QCborContainerPrivate::valueAt().

Referenced by QCborValueConstRef::taggedValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toArray() [1/2]

QCborArray QCborValue::toArray ( ) const

Definition at line 2312 of file qcborvalue.cpp.

References QCborArray, and toArray().

Referenced by Interface::Interface(), QImageReaderWriterHelpers::appendImagePluginMimeTypes(), QGeoServiceProviderPrivate::features(), MetaTypesJsonProcessor::processTypes(), toArray(), QCborValueConstRef::toArray(), and QCborValueConstRef::toArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toArray() [2/2]

QCborArray QCborValue::toArray ( const QCborArray & defaultValue) const

Returns the array value stored in this QCborValue, if it is of the array type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QCborArray.

See also
isArray(), isByteArray(), isMap(), isContainer(), toMap()

Definition at line 2317 of file qcborvalue.cpp.

References isArray(), Q_ASSERT, and QCborArray.

+ Here is the call graph for this function:

◆ toBool()

bool QCborValue::toBool ( bool defaultValue = false) const
inline

Returns the boolean value stored in this QCborValue, if it is of a boolean type.

Otherwise, it returns defaultValue.

See also
isBool(), isTrue(), isFalse()

Definition at line 189 of file qcborvalue.h.

Referenced by QLibraryPrivate::updatePluginState().

+ Here is the caller graph for this function:

◆ toByteArray()

QByteArray QCborValue::toByteArray ( const QByteArray & defaultValue = {}) const

Returns the byte array value stored in this QCborValue, if it is of the byte array type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QByteArray.

See also
isByteArray(), isString(), toString()

Definition at line 2170 of file qcborvalue.cpp.

References QCborContainerPrivate::byteArrayAt(), isByteArray(), and Q_ASSERT.

+ Here is the call graph for this function:

◆ toDateTime()

QDateTime QCborValue::toDateTime ( const QDateTime & defaultValue = {}) const

Returns the date/time value stored in this QCborValue, if it is of the date/time extended type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QDateTime.

See also
isDateTime(), isTag(), taggedValue()

Definition at line 2206 of file qcborvalue.cpp.

References QtCbor::ByteData::asLatin1(), QList< T >::at(), QCborContainerPrivate::byteData(), QCborContainerPrivate::elements, QtCbor::Element::flags, isDateTime(), Qt::ISODateWithMs, Q_ASSERT, and QList< T >::size().

+ Here is the call graph for this function:

◆ toDiagnosticNotation()

QString QCborValue::toDiagnosticNotation ( DiagnosticNotationOptions opts = Compact) const

Creates the diagnostic notation equivalent of this CBOR object and returns it.

The opts parameter controls the dialect of the notation. Diagnostic notation is useful in debugging, to aid the developer in understanding what value is stored in the QCborValue or in a CBOR stream. For that reason, the Qt API provides no support for parsing the diagnostic back into the in-memory format or CBOR stream, though the representation is unique and it would be possible.

CBOR diagnostic notation is specified by \l{RFC 7049, section 6}{section 6} of RFC 7049. It is a text representation of the CBOR stream and it is very similar to JSON, but it supports the CBOR types not found in JSON. The extended format enabled by the \l{DiagnosticNotationOption}{ExtendedFormat} flag is currently in some IETF drafts and its format is subject to change.

This function produces the equivalent representation of the stream that toCbor() would produce, without any transformation option provided there. This also implies this function may not produce a representation of the stream that was used to create the object, if it was created using fromCbor(), as that function may have applied transformations. For a high-fidelity notation of a stream, without transformation, see the cbordump example.

See also
toCbor(), QJsonDocument::toJson()

Definition at line 311 of file qcbordiagnostic.cpp.

◆ toDouble()

double QCborValue::toDouble ( double defaultValue = 0) const
inline

Returns the floating point value stored in this QCborValue, if it is of the Double type.

If it is of the Integer type, this function returns the integer value converted to double. In any other case, it returns defaultValue.

See also
isDouble(), isInteger(), toInteger()

Definition at line 191 of file qcborvalue.h.

Referenced by QGeoPositionInfoSourcePrivate::loadFactory().

+ Here is the caller graph for this function:

◆ toInteger()

qint64 QCborValue::toInteger ( qint64 defaultValue = 0) const
inline

Returns the integer value stored in this QCborValue, if it is of the integer type.

If it is of the Double type, this function returns the floating point value converted to integer. In any other case, it returns defaultValue.

See also
isInteger(), isDouble(), toDouble()

Definition at line 187 of file qcborvalue.h.

Referenced by QLibraryPrivate::updatePluginState().

+ Here is the caller graph for this function:

◆ toJsonValue()

QJsonValue QCborValue::toJsonValue ( ) const

Converts this QCborValue object to an equivalent representation in JSON and returns it as a QJsonValue.

Please note that CBOR contains a richer and wider type set than JSON, so some information may be lost in this conversion. The following table compares CBOR types to JSON types and indicates whether information may be lost or not.

\table \header

  • CBOR Type
  • JSON Type
  • Comments \row
  • Bool
  • Bool
  • No data loss possible \row
  • Double
  • Number
  • Infinities and NaN will be converted to Null; no data loss for other values \row
  • Integer
  • Number
  • Data loss possible in the conversion if the integer is larger than 2\sup{53} or smaller than -2\sup{53}. \row
  • Null
  • Null
  • No data loss possible \row
  • Undefined
  • Null
  • Type information lost \row
  • String
  • String
  • No data loss possible \row
  • Byte Array
  • String
  • Converted to a lossless encoding like Base64url, but the distinction between strings and byte arrays is lost \row
  • Other simple types
  • String
  • Type information lost \row
  • Array
  • Array
  • Conversion applies to each contained value \row
  • Map
  • Object
  • Keys are converted to string; values converted according to this table \row
  • Tags and extended types
  • Special
  • The tag number itself is lost and the tagged value is converted to JSON \endtable

For information on the conversion of CBOR map keys to string, see QCborMap::toJsonObject().

If this QCborValue contains the undefined value, this function will return an undefined QJsonValue too. Note that JSON does not support undefined values and undefined QJsonValues are an extension to the specification. They cannot be held in a QJsonArray or QJsonObject, but can be returned from functions to indicate a failure. For all other intents and purposes, they are the same as null.

Definition at line 349 of file qjsoncbor.cpp.

References Array, ByteArray, DateTime, Double, False, fpToJson(), QJsonPrivate::Value::fromTrustedCbor(), Integer, Invalid, Map, Null, qt_convertToJson(), RegularExpression, SimpleType, simpleTypeString(), String, QJsonValue::String, Tag, True, type(), Undefined, QJsonValue::Undefined, Url, and Uuid.

+ Here is the call graph for this function:

◆ toMap() [1/2]

QCborMap QCborValue::toMap ( ) const

Definition at line 2355 of file qcborvalue.cpp.

References QCborMap, and toMap().

Referenced by Interface::Interface(), QImageReaderWriterHelpers::appendImagePluginMimeTypes(), MetaTypesJsonProcessor::processTypes(), toMap(), QCborValueConstRef::toMap(), and QCborValueConstRef::toMap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toMap() [2/2]

QCborMap QCborValue::toMap ( const QCborMap & defaultValue) const

Returns the map value stored in this QCborValue, if it is of the map type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QCborMap.

See also
isMap(), isArray(), isContainer(), toArray()

Definition at line 2360 of file qcborvalue.cpp.

References isMap(), Q_ASSERT, and QCborMap.

+ Here is the call graph for this function:

◆ toSimpleType()

QCborSimpleType QCborValue::toSimpleType ( QCborSimpleType defaultValue = QCborSimpleType::Undefined) const
inline

Returns the simple type this QCborValue is of, if it is a simple type.

If it is not a simple type, it returns defaultValue.

The following types are simple types and this function will return the listed values:

\table \row

See also
type(), isSimpleType(), isBool(), isTrue(), isFalse(), isTrue(), isNull(), isUndefined()

Definition at line 182 of file qcborvalue.h.

References isSimpleType().

+ Here is the call graph for this function:

◆ toString()

QString QCborValue::toString ( const QString & defaultValue = {}) const

Returns the string value stored in this QCborValue, if it is of the string type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QString.

See also
isString(), isByteArray(), toByteArray()

Definition at line 2188 of file qcborvalue.cpp.

References isString(), Q_ASSERT, and QCborContainerPrivate::stringAt().

Referenced by QImageReaderWriterHelpers::appendImagePluginMimeTypes(), QGeoPositionInfoSourcePrivate::createSourceReal(), QGeoSatelliteInfoSourcePrivate::createSourceReal(), QmlLsp::OpenDocumentSnapshot::dump(), and QQmlLSUtils::fieldMemberExpressionBits().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toUrl()

QUrl QCborValue::toUrl ( const QUrl & defaultValue = {}) const

Returns the URL value stored in this QCborValue, if it is of the URL extended type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QUrl.

See also
isUrl(), isTag(), taggedValue()

Definition at line 2230 of file qcborvalue.cpp.

References QtCbor::ByteData::asByteArrayView(), QCborContainerPrivate::byteData(), QCborContainerPrivate::elements, QUrl::fromEncoded(), isUrl(), Q_ASSERT, and QList< T >::size().

+ Here is the call graph for this function:

◆ toUuid()

QUuid QCborValue::toUuid ( const QUuid & defaultValue = {}) const

Returns the UUID value stored in this QCborValue, if it is of the UUID extended type.

Otherwise, it returns defaultValue.

Note that this function performs no conversion from other types to QUuid.

See also
isUuid(), isTag(), taggedValue()

Definition at line 2272 of file qcborvalue.cpp.

References QtCbor::ByteData::asByteArrayView(), QCborContainerPrivate::byteData(), QCborContainerPrivate::elements, QUuid::fromRfc4122(), isUuid(), Q_ASSERT, and QList< T >::size().

+ Here is the call graph for this function:

◆ toVariant()

QVariant QCborValue::toVariant ( ) const

Converts this value to a native Qt type and returns the corresponding QVariant.

The following table lists the mapping performed between \l{Type}{QCborValue types} and \l{QMetaType::Type}{Qt meta types}.

\table \header

  • CBOR Type
  • Qt or C++ type
  • Notes \row
  • Integer
  • \l qint64
  • \row
  • Double
  • double
  • \row
  • Bool
  • bool
  • \row
  • Null
  • std::nullptr_t
  • \row
  • Undefined
  • no type (QVariant())
  • \row
  • Byte array
  • \l QByteArray
  • \row
  • String
  • \l QString
  • \row
  • Array
  • \l QVariantList
  • Recursively converts all values \row
  • Map
  • \l QVariantMap
  • Key types are "stringified" \row
  • Other simple types
  • \l QCborSimpleType
  • \row
  • DateTime
  • \l QDateTime
  • \row
  • Url
  • \l QUrl
  • \row
  • RegularExpression
  • \l QRegularExpression
  • \row
  • Uuid
  • \l QUuid
  • \row
  • Other tags
  • Special
  • The tag is ignored and the tagged value is converted using this function \endtable

Note that values in both CBOR Maps and Arrays are converted recursively using this function too and placed in QVariantMap and QVariantList instead. You will not find QCborMap and QCborArray stored inside the QVariants.

QVariantMaps have string keys, unlike CBOR, so the conversion of a QCborMap to QVariantMap will imply a step of "stringification" of the key values. See QCborMap::toJsonObject() for details.

See also
fromVariant(), toJsonValue(), QCborArray::toVariantList(), QCborMap::toVariantMap()

Definition at line 518 of file qjsoncbor.cpp.

References False, QVariant::fromValue(), Invalid, isSimpleType(), Null, RegularExpression, toDouble(), toMap(), toString(), True, Undefined, Url, and Uuid.

+ Here is the call graph for this function:

◆ type()

QCborValue::Type QCborValue::type ( ) const
inline

Returns the type of this QCborValue.

The type can also later be retrieved by one of the "isXxx" functions.

See also
isInteger(), isByteArray(), isString(), isArray(), isMap(), isTag(), isFalse(), isTrue(), isBool(), isNull(), isUndefined, isDouble(), isDateTime(), isUrl(), isRegularExpression(), isUuid()

Definition at line 154 of file qcborvalue.h.

Referenced by QQmlJS::Dom::domCompareStrList(), and toJsonValue().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ comparesEqual

Q_CORE_EXPORT Q_DECL_PURE_FUNCTION bool comparesEqual ( const QCborValue & lhs,
const QCborValue & rhs )
friend

Definition at line 1368 of file qcborvalue.cpp.

◆ compareThreeWay

Qt::strong_ordering compareThreeWay ( const QCborValue & lhs,
const QCborValue & rhs )
friend

Definition at line 254 of file qcborvalue.h.

◆ QCborArray

friend class QCborArray
friend

Definition at line 262 of file qcborvalue.h.

Referenced by toArray(), and toArray().

◆ QCborContainerPrivate

friend class QCborContainerPrivate
friend

Definition at line 266 of file qcborvalue.h.

◆ QCborMap

friend class QCborMap
friend

Definition at line 263 of file qcborvalue.h.

Referenced by toMap(), and toMap().

◆ QCborValueConstRef

friend class QCborValueConstRef
friend

Definition at line 264 of file qcborvalue.h.

◆ QCborValueRef

friend class QCborValueRef
friend

Definition at line 265 of file qcborvalue.h.

◆ QJsonPrivate::Value

friend class QJsonPrivate::Value
friend

Definition at line 267 of file qcborvalue.h.


The documentation for this class was generated from the following files: