diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2012-03-02 14:48:09 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-06 13:37:17 +0100 |
commit | eb24dfcccb304c84a147f0eafd3b3fc3df3ef4f3 (patch) | |
tree | 24f6ed9f377f52a69006488ba24af4762581105b /tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | |
parent | 9a5c728e4664cdd22ab999a9c7c15b7ed4965ce1 (diff) |
Add template specialization of QMetaType for QObject derived pointers.
This makes it possible to do things like
QVariant::fromValue(new SomeObject);
without first using Q_DECLARE_METATYPE(Something*)
This functionality was originally part of
http://codereview.qt-project.org/#change,11710 but was rejected
because the functionality was based on specialization of
QVariant::fromValue which could be dangerous.
This new implementation doesn't have such danger.
Change-Id: I83fe941b6984be54469bc6b9191f6eacaceaa036
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp')
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index ccdab17668..5aa1389b65 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2541,9 +2541,24 @@ public: }; Q_DECLARE_METATYPE(CustomQObjectDerived*) +class CustomQObjectDerivedNoMetaType : public CustomQObject { + Q_OBJECT +public: + CustomQObjectDerivedNoMetaType(QObject *parent = 0) : CustomQObject(parent) {} +}; + void tst_QVariant::qvariant_cast_QObject_derived() { { + CustomQObjectDerivedNoMetaType *object = new CustomQObjectDerivedNoMetaType(this); + QVariant data = QVariant::fromValue(object); + QVERIFY(data.userType() == qMetaTypeId<CustomQObjectDerivedNoMetaType*>()); + QCOMPARE(data.value<QObject *>(), object); + QCOMPARE(data.value<CustomQObjectDerivedNoMetaType *>(), object); + QCOMPARE(data.value<CustomQObject *>(), object); + QVERIFY(data.value<CustomQWidget*>() == 0); + } + { CustomQObjectDerived *object = new CustomQObjectDerived(this); QVariant data = QVariant::fromValue(object); |