From 8f040ea4da93f1b9cae1db560e5e9f9b3140b3ff Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 27 Oct 2009 13:48:39 +0100 Subject: QVariant::isNull does not return the right result with QVariant::setValue Inspired by merge request 1911 Reveiwed-by: Thierry --- src/corelib/kernel/qvariant.h | 1 + tests/auto/qvariant/tst_qvariant.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index eb4fb56..4cce529 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -460,6 +460,7 @@ inline void qVariantSetValue(QVariant &v, const T &t) QVariant::Private &d = v.data_ptr(); if (v.isDetached() && (type <= int(QVariant::Char) || type == d.type)) { d.type = type; + d.is_null = false; T *old = reinterpret_cast(d.is_shared ? d.data.shared->ptr : &d.data.ptr); if (QTypeInfo::isComplex) old->~T(); diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 9295897..de4d7b4 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -318,6 +318,14 @@ void tst_QVariant::constructor() QVariant var6(qlonglong(0)); QCOMPARE(var6.type(), QVariant::LongLong); QCOMPARE(var6.typeName(), "qlonglong"); + + QVariant var7 = 5; + QVERIFY(var7.isValid()); + QVERIFY(!var7.isNull()); + QVariant var8; + var8.setValue(5); + QVERIFY(var8.isValid()); + QVERIFY(!var8.isNull()); } void tst_QVariant::copy_constructor() -- cgit v0.12