Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73196

QVariant::isNull returns true after successfully downcasting a non-null Value

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.14.0 Alpha
    • 5.11.3
    • None
    • Linux 4.19.12 on Debian Buster/Testing.
    • All
    • 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).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            dreamcooled Mr Dreamcooled
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes