diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2012-06-06 14:12:01 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-07 12:20:32 +0200 |
commit | e58931462e3c32434d070058b87e5d9152ed004e (patch) | |
tree | 7ca61717769ba0b2a7c92a4f26136a8613054b70 /src/qml/qml/qqmlengine.cpp | |
parent | c7ad506a4e46d3b3a2d3f6235e5c7df69b027311 (diff) |
Don't double emit threaded signals
As the metacall event was posted to the object emitting the signal, it
caused the signal to be *reemitted* on the object thread. If both QML
and Qt connections were present, the Qt ones were run twice.
Change-Id: I4bc1402ab0a43762ff6fef173ecc77fc20508bad
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlengine.cpp')
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 832f58bcfa..b122d74df4 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -472,6 +472,25 @@ void QQmlData::parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p static_cast<QQmlData *>(d)->parentChanged(o, p); } +class QQmlThreadNotifierProxyObject : public QObject +{ +public: + QPointer<QObject> target; + + virtual int qt_metacall(QMetaObject::Call, int id, void **a) { + if (!target) + return -1; + + QQmlData *ddata = QQmlData::get(target, false); + QQmlNotifierEndpoint *ep = ddata->notify(id); + if (ep) QQmlNotifier::emitNotify(ep, a); + + delete this; + + return -1; + } +}; + void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int index, void **a) { QQmlData *ddata = QQmlData::get(object, false); @@ -486,6 +505,9 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in if (ddata->notifyList && QThread::currentThreadId() != QObjectPrivate::get(object)->threadData->threadId) { + if (!QObjectPrivate::get(object)->threadData->thread) + return; + QMetaMethod m = object->metaObject()->method(index); QList<QByteArray> parameterTypes = m.parameterTypes(); @@ -516,7 +538,11 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in QMetaCallEvent *ev = new QMetaCallEvent(index, 0, 0, object, index, parameterTypes.count() + 1, types, args); - QCoreApplication::postEvent(object, ev); + + QQmlThreadNotifierProxyObject *mpo = new QQmlThreadNotifierProxyObject; + mpo->target = object; + mpo->moveToThread(QObjectPrivate::get(object)->threadData->thread); + QCoreApplication::postEvent(mpo, ev); } else { QQmlNotifierEndpoint *ep = ddata->notify(index); |