From 26a81bd4fb1f382b2b1652566652301cfe1270a2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 20 May 2024 11:31:02 -0500 Subject: [PATCH] QVariant: do reset is_null after setValue() Issue introduced by a68e4f3b96a82a93898f381e8ddc7f50f9c89d40 ("Use the new QMetaType API in QVariant") in 6.0, which removed the d.is_null reset at the same time as it replaced the std::destroy_at / std::construct_at pair with an assignment operation. [ChangeLog][QtCore][QVariant] Fixed a bug that would allow the class to keep returning isNull() = true even after calling setValue(). Fixes: QTBUG-125472 Pick-to: 6.5 6.7 Change-Id: If05cb740b64f42eba21efffd17d13f6b1e8113c2 Reviewed-by: Fabian Kosmale Reviewed-by: Christian Ehrlicher Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qvariant.h | 1 + tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index d567bcbb7c..306e5b3a38 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -497,6 +497,7 @@ public: // If possible we reuse the current QVariant private. if (isDetached() && d.type() == metaType) { *reinterpret_cast(const_cast(constData())) = std::forward(avalue); + d.is_null = false; } else { *this = QVariant::fromValue(std::forward(avalue)); } diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 23d41cafb2..a8e2c7bda3 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -544,6 +544,9 @@ void tst_QVariant::isNull() var3 = QVariant(QMetaType::fromType()); QVERIFY( var3.isNull() ); + var3.setValue(QString()); + QVERIFY( !var3.isNull() ); + QVariant var4( 0 ); QVERIFY( !var4.isNull() );