Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.11.3
-
None
-
Linux 4.19.12 on Debian Buster/Testing.
-
-
758151d077536eb8fe2cd1a3252dec5619b9789f (qt/qtbase/dev)
Description
When storing a QObject derived class T in a QVariant as QObject* and then trying to cast it to T*, QVariant::isNull returns true even though the value can be received via QVariant::value<T*>()
Full testcase:
// Put this testcase in tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp // Function: void tst_QVariant::qvariant_cast_QObject_derived() QObject *object = new CustomQObjectDerivedNoMetaType(this); QVariant data = QVariant::fromValue(object); QVERIFY(data.canConvert<CustomQObjectDerivedNoMetaType*>()); QVERIFY(data.convert(qMetaTypeId<CustomQObjectDerivedNoMetaType*>())); QCOMPARE(data.value<CustomQObjectDerivedNoMetaType*>(), object); QCOMPARE(data.isNull(), false); //fails here. Code above runs fine
I think this is a pretty serious bug, since the wrong value of isNull will cause subsequent QVariant calls to fail (e.g. QVariant::save).