diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index deba977f77..77d2c8cbe1 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -1462,6 +1462,7 @@ static void customConstruct(QVariant::Private *d, const void *copy) if (size <= sizeof(QVariant::Private::Data) && (type.flags() & (QMetaType::MovableType | QMetaType::IsEnumeration))) { type.construct(&d->data.ptr, copy); + d->is_null = d->data.ptr == nullptr; d->is_shared = false; } else { // Private::Data contains long long, and long double is the biggest standard type. @@ -1472,6 +1473,7 @@ static void customConstruct(QVariant::Private *d, const void *copy) void *data = operator new(offset + size); void *ptr = static_cast(data) + offset; type.construct(ptr, copy); + d->is_null = ptr == nullptr; d->is_shared = true; d->data.shared = new (data) QVariant::PrivateShared(ptr); } diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 4da34c407e..a9162a6a6f 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2761,6 +2761,14 @@ void tst_QVariant::qvariant_cast_QObject_derived() QCOMPARE(data.value(), object); QCOMPARE(data.value(), object); } + { + QObject *object = new CustomQObjectDerivedNoMetaType(this); + QVariant data = QVariant::fromValue(object); + QVERIFY(data.canConvert()); + QVERIFY(data.convert(qMetaTypeId())); + QCOMPARE(data.value(), object); + QCOMPARE(data.isNull(), false); + } } struct QObjectWrapper