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:
Stephen Kelly 2013-09-05 11:13:26 +02:00 committed by The Qt Project
parent d1a8623ecb
commit f69ace7341
2 changed files with 4 additions and 1 deletions

View File

@ -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
};

View File

@ -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);