diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2019-12-13 18:07:26 +0100 |
---|---|---|
committer | Arno Rehn <a.rehn@menlosystems.com> | 2021-04-16 14:04:38 +0200 |
commit | 28455e59c0b940200fe0223472a80104ce1a02dd (patch) | |
tree | 73ee9356efac20f704e43213250bcc6f46f761ad /src/webchannel/signalhandler_p.h | |
parent | e4c7122d78e4f8dccc246a027cde1bf43a87841d (diff) |
Handle signals in the registered object's thread
Do not call `sender()` from a different thread. As the API documentation
indicates, that is not supported and can lead to crashes as experienced
on the CI frequently.
Instead, we now have per-thread SignalHandlers and use those to get
notified about signals and metacall events.
Moving a registered object into a different thread isn't supported once
it was registered. But the object can be deregistered, moved, and then
re-registered.
[ChangeLog] Signals from objects living in a different thread than the
QWebChannel are now handled correctly.
Task-number: QTBUG-51366
Change-Id: I1edb0694b946a494b6c0d4a8a6dc6b452dcb2c7a
Reviewed-by: Arno Rehn <a.rehn@menlosystems.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/webchannel/signalhandler_p.h')
-rw-r--r-- | src/webchannel/signalhandler_p.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/webchannel/signalhandler_p.h b/src/webchannel/signalhandler_p.h index 8fdf598..942c020 100644 --- a/src/webchannel/signalhandler_p.h +++ b/src/webchannel/signalhandler_p.h @@ -56,6 +56,7 @@ #include <QList> #include <QMetaMethod> #include <QDebug> +#include <QThread> QT_BEGIN_NAMESPACE @@ -71,6 +72,7 @@ static const int s_destroyedSignalIndex = QObject::staticMetaObject.indexOfMetho template<class Receiver> class SignalHandler : public QObject { + Q_DISABLE_COPY(SignalHandler) public: SignalHandler(Receiver *receiver, QObject *parent = 0); @@ -268,6 +270,7 @@ int SignalHandler<Receiver>::qt_metacall(QMetaObject::Call call, int methodId, v if (call == QMetaObject::InvokeMetaMethod) { const QObject *object = sender(); Q_ASSERT(object); + Q_ASSERT(QThread::currentThread() == object->thread()); Q_ASSERT(senderSignalIndex() == methodId); Q_ASSERT(m_connectionsCounter.contains(object)); Q_ASSERT(m_connectionsCounter.value(object).contains(methodId)); |