From 86379e265e19a078545306d93c59b0d92c04920a Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Thu, 1 Oct 2020 15:30:53 +0200 Subject: QQmlProperty::write: historical reason does not hold in Qt 6 There was a codepath which checked after a failed QVariant conversion whether the variant is valid and is null at the same time. In that case, the conversion would be treated as successful. The motivation for this can be traced back to QTBUG-37197, and our handling of strings. However, since those times various things have changed: - QVariant::isNull() does not return true anymore if its contained type is null. Thus the conversion of a QVariant holding a null QString will not lead to a conversion failure (as long as the target type is actually a conversion target for a QString). - A failed conversion will always leave the resulting variant in a state in which it is valid. The latter is rather problematic, as we would thus always enter the code path when the source QVariant happened to be null; even in the case where the source and target types are really incompatible. This can for instance be observed in tst_qjsonbinding, where assigning null to a QJsonArray would suddenly "work", thus leading to a test failure. However, thanks to the first point, it is safe to completely remove this code. Change-Id: I176a5c4b04295d128919cab8a333b8a5a2c2345d Reviewed-by: Ulf Hermann Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlproperty.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/qml/qml/qqmlproperty.cpp') diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index afdec1d450..a30314635a 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -1372,12 +1372,6 @@ bool QQmlPropertyPrivate::write( v = value; if (v.convert(QMetaType(propertyType))) { ok = true; - } else if (v.isValid() && value.isNull()) { - // For historical reasons converting a null QVariant to another type will do the trick - // but return false anyway. This is caught with the above condition and considered a - // successful conversion. - Q_ASSERT(v.userType() == propertyType); - ok = true; } else if (static_cast(propertyType) >= QMetaType::User && variantType == QMetaType::QString) { QQmlMetaType::StringConverter con = QQmlMetaType::customStringConverter(propertyType); -- cgit v1.2.3