From 6b4f8a68c8da1af7c5be7dc6075b688c9d6ca55f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 31 Dec 2011 07:25:07 +0100 Subject: Automated metatype definition for template types. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If T is defined as a metatype, then QList is too automatically. So for example, no need to use Q_DECLARE_METATYPE(QList) anymore. This is a source compatible change. Change-Id: I2ee8a7b9e28fe6d4775f6a05cce39aca8563e0c5 Reviewed-by: Jędrzej Nowacki Reviewed-by: João Abecasis --- .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index de93c21d43..19aa6877b2 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -89,6 +89,7 @@ private slots: void isRegistered(); void unregisterType(); void registerStreamBuiltin(); + void automaticTemplateRegistration(); }; struct Foo { int i; }; @@ -888,5 +889,50 @@ void tst_QMetaType::registerStreamBuiltin() qRegisterMetaTypeStreamOperators("QVariant"); } +Q_DECLARE_METATYPE(QSharedPointer) + +void tst_QMetaType::automaticTemplateRegistration() +{ + { + QList intList; + intList << 42; + QVERIFY(QVariant::fromValue(intList).value >().first() == 42); + QVector > vectorList; + vectorList << intList; + QVERIFY(QVariant::fromValue(vectorList).value > >().first().first() == 42); + } + + { + QList bytearrayList; + bytearrayList << QByteArray("foo"); + QVERIFY(QVariant::fromValue(bytearrayList).value >().first() == QByteArray("foo")); + QVector > vectorList; + vectorList << bytearrayList; + QVERIFY(QVariant::fromValue(vectorList).value > >().first().first() == QByteArray("foo")); + } + + QCOMPARE(::qMetaTypeId(), (int)QMetaType::QVariantList); + QCOMPARE(::qMetaTypeId >(), (int)QMetaType::QVariantList); + + { + QList variantList; + variantList << 42; + QVERIFY(QVariant::fromValue(variantList).value >().first() == 42); + QVector > vectorList; + vectorList << variantList; + QVERIFY(QVariant::fromValue(vectorList).value > >().first().first() == 42); + } + + { + QList > sharedPointerList; + QObject *testObject = new QObject; + sharedPointerList << QSharedPointer(testObject); + QVERIFY(QVariant::fromValue(sharedPointerList).value > >().first() == testObject); + QVector > > vectorList; + vectorList << sharedPointerList; + QVERIFY(QVariant::fromValue(vectorList).value > > >().first().first() == testObject); + } +} + QTEST_MAIN(tst_QMetaType) #include "tst_qmetatype.moc" -- cgit v1.2.3