diff options
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache')
-rw-r--r-- | tests/auto/qml/qqmlpropertycache/data/passQGadget.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp | 39 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/data/passQGadget.qml b/tests/auto/qml/qqmlpropertycache/data/passQGadget.qml new file mode 100644 index 0000000000..86fdd920ed --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/passQGadget.qml @@ -0,0 +1,12 @@ +import QtQml 2.2 + +QtObject { + property var result; + + property Connections connections: Connections { + target: emitter + onEmitGadget: function(gadget) { + result = gadget.someProperty; + } + } +} diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index 1c8e3c50ab..f577a091eb 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -50,6 +50,7 @@ private slots: void signalHandlers(); void signalHandlersDerived(); void passForeignEnums(); + void passQGadget(); void metaObjectSize_data(); void metaObjectSize(); void metaObjectChecksum(); @@ -338,6 +339,44 @@ void tst_qqmlpropertycache::passForeignEnums() Q_DECLARE_METATYPE(MyEnum::Option1) +QT_BEGIN_NAMESPACE +class SimpleGadget +{ + Q_GADGET + Q_PROPERTY(bool someProperty READ someProperty) +public: + bool someProperty() const { return true; } +}; + +// Avoids NeedsCreation and NeedsDestruction flags +Q_DECLARE_TYPEINFO(SimpleGadget, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE + +class GadgetEmitter : public QObject +{ + Q_OBJECT +signals: + void emitGadget(SimpleGadget); +}; + +void tst_qqmlpropertycache::passQGadget() +{ + qRegisterMetaType<SimpleGadget>(); + + GadgetEmitter emitter; + engine.rootContext()->setContextProperty("emitter", &emitter); + QQmlComponent component(&engine, testFile("passQGadget.qml")); + QVERIFY(component.isReady()); + + QScopedPointer<QObject> obj(component.create(engine.rootContext())); + QVariant before = obj->property("result"); + QVERIFY(before.isNull()); + emit emitter.emitGadget(SimpleGadget()); + QVariant after = obj->property("result"); + QCOMPARE(QMetaType::Type(after.type()), QMetaType::Bool); + QVERIFY(after.toBool()); +} + class TestClass : public QObject { Q_OBJECT |