QVariant: Make it possible to extract a QObject* from a wrapper without conversion.
Change-Id: I3a054d87d12e08d72dd4c77b6d467dc63f9a2231 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
d1a8623ecb
commit
f69ace7341
@ -756,7 +756,9 @@ namespace QtPrivate {
|
||||
#ifndef QT_NO_QOBJECT
|
||||
static T object(const QVariant &v)
|
||||
{
|
||||
return qobject_cast<T>(QMetaType::typeFlags(v.userType()) & QMetaType::PointerToQObject ? v.d.data.o : 0);
|
||||
return qobject_cast<T>(QMetaType::typeFlags(v.userType()) & QMetaType::PointerToQObject
|
||||
? v.d.data.o
|
||||
: QVariantValueHelper::metaType(v));
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
@ -2266,6 +2266,7 @@ void tst_QVariant::qvariant_cast_QObject_wrapper()
|
||||
CustomQObjectDerived *object = new CustomQObjectDerived(this);
|
||||
QObjectWrapper wrapper(object);
|
||||
QVariant v = QVariant::fromValue(wrapper);
|
||||
QCOMPARE(v.value<QObject*>(), object);
|
||||
v.convert(qMetaTypeId<QObject*>());
|
||||
QCOMPARE(v.value<QObject*>(), object);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user