diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2012-05-11 14:13:47 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-11 17:23:20 +0200 |
commit | 5570040771ec610583473e2d9e8e069474364cf1 (patch) | |
tree | cb3b406776731996783cdcab3704a2338b944b11 /tests | |
parent | 125f4ceb393886015574a3c3fd0fc264a4f2deb6 (diff) |
Permit signals to be emitted in a different thread
The QQmlNotifier approach to connecting to signals did not
support the cross-thread signal/slot model used elsewhere in
Qt. This change allows one specific case of that - emitting
a signal in a different thread than the one the QObject
lives - to work.
Task-number: QTBUG-25647
Change-Id: Ia8fdaf4c7d7e2ccd7ff7657bb1d8e26277eb60aa
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/threadSignal.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.cpp | 19 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 11 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 12 |
4 files changed, 49 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/threadSignal.qml b/tests/auto/qml/qqmlecmascript/data/threadSignal.qml new file mode 100644 index 0000000000..8f0e13b735 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/threadSignal.qml @@ -0,0 +1,8 @@ +import Qt.test 1.0 +import QtQuick 2.0 + +MyWorkerObject { + property bool passed: false + Component.onCompleted: doIt() + onDone: passed = (result == 'good') +} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp index d674fa3eb6..d3eff3b0ad 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.cpp +++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp @@ -43,6 +43,7 @@ #include <QPlainTextEdit> #include <QQmlEngine> #include <QJSEngine> +#include <QThread> class BaseExtensionObject : public QObject { @@ -154,6 +155,23 @@ static QObject *qobject_api_engine_parent(QQmlEngine *engine, QJSEngine *scriptE return o; } +class MyWorkerObjectThread : public QThread +{ +public: + MyWorkerObjectThread(MyWorkerObject *o) : QThread(o), o(o) { start(); } + + virtual void run() { + emit o->done(QLatin1String("good")); + } + + MyWorkerObject *o; +}; + +void MyWorkerObject::doIt() +{ + new MyWorkerObjectThread(this); +} + void registerTypes() { qmlRegisterType<MyQmlObject>("Qt.test", 1,0, "MyQmlObjectAlias"); @@ -170,6 +188,7 @@ void registerTypes() qmlRegisterType<MyRevisionedClass>("Qt.test",1,0,"MyRevisionedClass"); qmlRegisterType<MyDeleteObject>("Qt.test", 1,0, "MyDeleteObject"); qmlRegisterType<MyRevisionedClass,1>("Qt.test",1,1,"MyRevisionedClass"); + qmlRegisterType<MyWorkerObject>("Qt.test", 1,0, "MyWorkerObject"); // test scarce resource property binding post-evaluation optimisation // and for testing memory usage in property var circular reference test diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index e781e7703b..5fb78e81b6 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -1382,6 +1382,17 @@ private: QString m_timespec; }; +class MyWorkerObject : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + void doIt(); + +Q_SIGNALS: + void done(const QString &result); +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index a523bea003..40bff34ae2 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -261,8 +261,8 @@ private slots: void deleteRootObjectInCreation(); void onDestruction(); void bindingSuppression(); - void signalEmitted(); + void threadSignal(); private: static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -6760,6 +6760,16 @@ void tst_qqmlecmascript::signalEmitted() } } +// QTBUG-25647 +void tst_qqmlecmascript::threadSignal() +{ + QQmlComponent c(&engine, testFileUrl("threadSignal.qml")); + QObject *object = c.create(); + QVERIFY(object != 0); + QTRY_VERIFY(object->property("passed").toBool()); + delete object; +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" |