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

QVariant::canConvert behaves inconsistently with the documentation

    XMLWordPrintable

Details

    • 7cf49085e (dev), 79e3416bb (6.9), 6a0a181a1 (6.8)

    Description

      On Qt 6 QVariant::canConvert behaves differently than on Qt 5 and inconsistently with the documentation.

      The following code:

      QVariant variant = QVariant::fromValue(new QObject());
      qDebug() << variant.canConvert<QAbstractItemModel*>();
      qDebug() << variant.canConvert<QObject*>();

      prints false/true on Qt 5, but true/true on Qt 6.

       

      Moreover, according to docs

      A QVariant containing a pointer to a type derived from QObject will also return true for this function if a qobject_cast to the template type T would succeed. 

      what is not a case on a Qt 6, as

      qobject_cast<QAbstractItemModel*>(new QObject())

      gives null, obviously.

      Attachments

        For Gerrit Dashboard: QTBUG-135619
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            michalc Michał Cieślak
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes