summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/serialization/json
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-06-08 17:10:12 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-13 08:48:19 +0200
commit4a69cd7f72140c8f4c83f986b3366f7bd9ba69a3 (patch)
tree212a00a49c87cdddc623d00455ee9003f4baae50 /tests/auto/corelib/serialization/json
parent50c96c17b6c87d48418336dc124a6de3f1f1958b (diff)
Restrict comparison of variants
Comparing two variants will not try to convert the types of the variant anymore. Exceptions are when both types are numeric types or one type is numeric and the other one a QString. The exceptions are there to keep compatibility with C++ and to not completely break QSettings (which needs automatic conversions from QString to numeric types). [ChangeLog][Important Behavior Changes] Comparing two variants in Qt 6 will not try attempt any type conversions before comparing the variants anymore. Instead variants of different type will not compare equal, with two exceptions: If both types are numeric types they will get compared according to C++ type promotion rules. If one type is a QString and the other type a numeric type, a conversion from the string to the numeric tpye will be attempted. Fixes: QTBUG-84636 Change-Id: I0cdd0b7259a525a41679fb6761f1e37e1d5b257f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/serialization/json')
-rw-r--r--tests/auto/corelib/serialization/json/tst_qtjson.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
index 82ad404932..b11d8c996d 100644
--- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
@@ -1361,7 +1361,7 @@ void tst_QtJson::fromVariant_data()
jsonObject["null"] = QJsonValue::Null;
jsonObject["default"] = QJsonValue();
- QTest::newRow("default") << QVariant() << QJsonValue(QJsonValue::Null);
+ QTest::newRow("default") << QVariant() << QJsonValue();
QTest::newRow("nullptr") << QVariant::fromValue(nullptr) << QJsonValue(QJsonValue::Null);
QTest::newRow("bool") << QVariant(boolValue) << QJsonValue(boolValue);
QTest::newRow("int") << QVariant(intValue) << QJsonValue(intValue);
@@ -1391,6 +1391,14 @@ static QVariant normalizedVariant(const QVariant &v)
out << normalizedVariant(v);
return out;
}
+ case QMetaType::QStringList: {
+ const QStringList in = v.toStringList();
+ QVariantList out;
+ out.reserve(in.size());
+ for (const QString &v : in)
+ out << v;
+ return out;
+ }
case QMetaType::QVariantMap: {
const QVariantMap in = v.toMap();
QVariantMap out;
@@ -1400,7 +1408,7 @@ static QVariant normalizedVariant(const QVariant &v)
}
case QMetaType::QVariantHash: {
const QVariantHash in = v.toHash();
- QVariantHash out;
+ QVariantMap out;
for (auto it = in.begin(); it != in.end(); ++it)
out.insert(it.key(), normalizedVariant(it.value()));
return out;