Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.8, 6.9
-
None
-
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 |
637613,2 | QMetaType/QVariant: update docs that canConvert() operates on types | dev | qt/qtbase | Status: MERGED | +2 | 0 |
638912,2 | QMetaType/QVariant: update docs that canConvert() operates on types | 6.9 | qt/qtbase | Status: MERGED | +2 | 0 |
639298,2 | QMetaType/QVariant: update docs that canConvert() operates on types | 6.8 | qt/qtbase | Status: MERGED | +2 | 0 |