From 0d55d1c640eff6b1bb9fcfa8f9130635782e0c97 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 27 Jun 2020 10:40:37 -0700 Subject: Doc: improve documentation about QVariant to JSON lossy conversions Fixes: QTBUG-85299 Pick-to: 5.15 Change-Id: I24006db8360041f598c5fffd161c77638a54a27e Reviewed-by: Allan Sandfeld Jensen --- src/corelib/serialization/qjsoncbor.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/corelib/serialization/qjsoncbor.cpp') diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp index 8bb04fa3bf..e0eab74a02 100644 --- a/src/corelib/serialization/qjsoncbor.cpp +++ b/src/corelib/serialization/qjsoncbor.cpp @@ -679,17 +679,22 @@ static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) \row \li \l QUuid \li Uuid \endtable - For any other types, this function will return Null if the QVariant itself - is null, and otherwise will try to convert to string using - QVariant::toString(). If the conversion to string fails, this function - returns Undefined. + 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. QCborValue may be extended in the future to support - more types, which will result in a change in how this function performs - conversions. + 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. - \sa toVariant(), fromJsonValue(), QCborArray::toVariantList(), QCborMap::toVariantMap() + \sa toVariant(), fromJsonValue(), QCborArray::toVariantList(), QCborMap::toVariantMap(), QJsonValue::fromVariant() */ QCborValue QCborValue::fromVariant(const QVariant &variant) { -- cgit v1.2.3