QVariant to QJsonValue::Null conversion
Adds a few missing parts of the conversion from QVariant to QJsonValue after the introduction of the nullptr QVariant. The conversion the other way is already implemented. Change-Id: I8b25dec4b476c4761c5098a60944ff11c36f8bec Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
parent
c647728652
commit
baebb6aa26
@ -346,6 +346,12 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other)
|
||||
\header
|
||||
\li Source type
|
||||
\li Destination type
|
||||
\row
|
||||
\li
|
||||
\list
|
||||
\li QMetaType::Nullptr
|
||||
\endlist
|
||||
\li QJsonValue::Null
|
||||
\row
|
||||
\li
|
||||
\list
|
||||
@ -393,6 +399,8 @@ QJsonValue &QJsonValue::operator =(const QJsonValue &other)
|
||||
QJsonValue QJsonValue::fromVariant(const QVariant &variant)
|
||||
{
|
||||
switch (variant.userType()) {
|
||||
case QMetaType::Nullptr:
|
||||
return QJsonValue(Null);
|
||||
case QVariant::Bool:
|
||||
return QJsonValue(variant.toBool());
|
||||
case QVariant::Int:
|
||||
|
@ -3085,6 +3085,7 @@ bool QVariant::canConvert(int targetTypeId) const
|
||||
|
||||
if (currentType == QMetaType::QJsonValue) {
|
||||
switch (targetTypeId) {
|
||||
case QMetaType::Nullptr:
|
||||
case QMetaType::QString:
|
||||
case QMetaType::Bool:
|
||||
case QMetaType::Int:
|
||||
|
@ -1103,6 +1103,7 @@ void tst_QtJson::fromVariant()
|
||||
jsonObject["string"] = stringValue;
|
||||
jsonObject["array"] = jsonArray_variant;
|
||||
|
||||
QCOMPARE(QJsonValue::fromVariant(QVariant::fromValue(nullptr)), QJsonValue(QJsonValue::Null));
|
||||
QCOMPARE(QJsonValue::fromVariant(QVariant(boolValue)), QJsonValue(boolValue));
|
||||
QCOMPARE(QJsonValue::fromVariant(QVariant(intValue)), QJsonValue(intValue));
|
||||
QCOMPARE(QJsonValue::fromVariant(QVariant(uintValue)), QJsonValue(static_cast<double>(uintValue)));
|
||||
@ -1179,7 +1180,7 @@ void tst_QtJson::toVariantMap()
|
||||
array.append(true);
|
||||
array.append(999.);
|
||||
array.append(QLatin1String("string"));
|
||||
array.append(QJsonValue());
|
||||
array.append(QJsonValue::Null);
|
||||
object.insert("Array", array);
|
||||
|
||||
map = object.toVariantMap();
|
||||
@ -1203,12 +1204,12 @@ void tst_QtJson::toVariantHash()
|
||||
QVERIFY(hash.isEmpty());
|
||||
|
||||
object.insert("Key", QString("Value"));
|
||||
object.insert("null", QJsonValue());
|
||||
object.insert("null", QJsonValue::Null);
|
||||
QJsonArray array;
|
||||
array.append(true);
|
||||
array.append(999.);
|
||||
array.append(QLatin1String("string"));
|
||||
array.append(QJsonValue());
|
||||
array.append(QJsonValue::Null);
|
||||
object.insert("Array", array);
|
||||
|
||||
hash = object.toVariantHash();
|
||||
|
Loading…
Reference in New Issue
Block a user