aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlnotifier.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2012-05-11 14:13:47 +0100
committerQt by Nokia <qt-info@nokia.com>2012-05-11 17:23:20 +0200
commit5570040771ec610583473e2d9e8e069474364cf1 (patch)
treecb3b406776731996783cdcab3704a2338b944b11 /src/qml/qml/qqmlnotifier.cpp
parent125f4ceb393886015574a3c3fd0fc264a4f2deb6 (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 'src/qml/qml/qqmlnotifier.cpp')
-rw-r--r--src/qml/qml/qqmlnotifier.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlnotifier.cpp b/src/qml/qml/qqmlnotifier.cpp
index 1ed3a2957d..20b90a7111 100644
--- a/src/qml/qml/qqmlnotifier.cpp
+++ b/src/qml/qml/qqmlnotifier.cpp
@@ -41,6 +41,8 @@
#include "qqmlnotifier_p.h"
#include "qqmlproperty_p.h"
+#include <QtCore/qdebug.h>
+#include <private/qthread_p.h>
QT_BEGIN_NAMESPACE
@@ -67,10 +69,26 @@ void QQmlNotifier::emitNotify(QQmlNotifierEndpoint *endpoint, void **a)
else if (endpoint) endpoint->notifying = 0;
}
-void QQmlNotifierEndpoint::connect(QObject *source, int sourceSignal)
+void QQmlNotifierEndpoint::connect(QObject *source, int sourceSignal, QQmlEngine *engine)
{
disconnect();
+ Q_ASSERT(engine);
+ if (QObjectPrivate::get(source)->threadData->threadId !=
+ QObjectPrivate::get(engine)->threadData->threadId) {
+
+ QString sourceName;
+ QDebug(&sourceName) << source;
+ sourceName = sourceName.left(sourceName.length() - 1);
+ QString engineName;
+ QDebug(&engineName).nospace() << engine;
+ engineName = engineName.left(engineName.length() - 1);
+
+ qFatal("QQmlEngine: Illegal attempt to connect to %s that is in"
+ " a different thread than the QML engine %s.", qPrintable(sourceName),
+ qPrintable(engineName));
+ }
+
this->source = source;
this->sourceSignal = sourceSignal;
QQmlPropertyPrivate::flushSignal(source, sourceSignal);