Specialize MetaObjectForType for non-pointer QObject-derived types
QMetaTypeInterfaceWrapper tries to find the metaObjectFunction using the MetaObjectForType template. Using SFINAE, for a QObject, it should resolve to a suitable specialization. Such a specialization doesn't yet exist. It had to be created. The following path returns nullptr for registered meta types: auto metatype = QMetaType(typeId); requestedTestType.metaObject() -> returns nullptr since a bad template argument is fed to MetaObjectForType<T> in QMetaTypeInterfaceWrapper<IneritingFromQObject>::metaType's static initializer. Change-Id: I8b31c51e12cb19c333e00480b0177354b910ce1e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5e8cc498a1
commit
fd45278eaa
@ -901,7 +901,12 @@ namespace QtPrivate
|
||||
static constexpr const QMetaObject *metaObjectFunction(const QMetaTypeInterface *) { return &T::staticMetaObject; }
|
||||
};
|
||||
template<typename T>
|
||||
struct MetaObjectForType<T, typename std::enable_if<IsGadgetHelper<T>::IsGadgetOrDerivedFrom>::type>
|
||||
struct MetaObjectForType<T, std::enable_if_t<
|
||||
std::disjunction_v<
|
||||
std::bool_constant<IsGadgetHelper<T>::IsGadgetOrDerivedFrom>,
|
||||
std::is_base_of<QObject, T>
|
||||
>
|
||||
>>
|
||||
{
|
||||
static constexpr const QMetaObject *value() { return &T::staticMetaObject; }
|
||||
static constexpr const QMetaObject *metaObjectFunction(const QMetaTypeInterface *) { return &T::staticMetaObject; }
|
||||
|
@ -1999,6 +1999,7 @@ void tst_QMetaType::metaObject_data()
|
||||
QTest::newRow("unknown-type") << int(QMetaType::UnknownType) << static_cast<const QMetaObject *>(0) << false << false << false;
|
||||
QTest::newRow("QObject") << int(QMetaType::QObjectStar) << &QObject::staticMetaObject << false << false << true;
|
||||
QTest::newRow("QFile*") << ::qMetaTypeId<QFile*>() << &QFile::staticMetaObject << false << false << true;
|
||||
QTest::newRow("MyObject") << ::qMetaTypeId<MyObject>() << &MyObject::staticMetaObject << false << false << false;
|
||||
QTest::newRow("MyObject*") << ::qMetaTypeId<MyObject*>() << &MyObject::staticMetaObject << false << false << true;
|
||||
QTest::newRow("int") << int(QMetaType::Int) << static_cast<const QMetaObject *>(0) << false << false << false;
|
||||
QTest::newRow("QEasingCurve") << ::qMetaTypeId<QEasingCurve>() << &QEasingCurve::staticMetaObject << true << false << false;
|
||||
|
Loading…
Reference in New Issue
Block a user