QVariant: do reset is_null after setValue()

Issue introduced by a68e4f3b96 ("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 <fabian.kosmale@qt.io>
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Thiago Macieira 2024-05-20 11:31:02 -05:00
parent 067f60f792
commit 26a81bd4fb
2 changed files with 4 additions and 0 deletions

View File

@ -497,6 +497,7 @@ public:
// If possible we reuse the current QVariant private.
if (isDetached() && d.type() == metaType) {
*reinterpret_cast<VT *>(const_cast<void *>(constData())) = std::forward<T>(avalue);
d.is_null = false;
} else {
*this = QVariant::fromValue<VT>(std::forward<T>(avalue));
}

View File

@ -544,6 +544,9 @@ void tst_QVariant::isNull()
var3 = QVariant(QMetaType::fromType<QString>());
QVERIFY( var3.isNull() );
var3.setValue(QString());
QVERIFY( !var3.isNull() );
QVariant var4( 0 );
QVERIFY( !var4.isNull() );