From 843b0b819ba38807fd8c2f2965ee3382d8fffd68 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 Change-Id: If05cb740b64f42eba21efffd17d13f6b1e8113c2 Reviewed-by: Fabian Kosmale Reviewed-by: Christian Ehrlicher Reviewed-by: Volker Hilsheimer (cherry picked from commit 26a81bd4fb1f382b2b1652566652301cfe1270a2) Reviewed-by: Qt Cherry-pick Bot --- 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 6d51d940c5b..dcfc10dc151 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -496,6 +496,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 68ab515623a..1a6608875f6 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -541,6 +541,9 @@ void tst_QVariant::isNull() var3 = QVariant(QMetaType::fromType()); QVERIFY( var3.isNull() ); + var3.setValue(QString()); + QVERIFY( !var3.isNull() ); + QVariant var4( 0 ); QVERIFY( !var4.isNull() );