From 3c551005dcb8de4bb083aa934a8fdff1298f14f9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 16 Sep 2020 08:11:29 +0200 Subject: Fix slots being invoked from the wrong thread In case the signal connections are routed via some GlobalReceiverV2 instance, it needs to be moved to the receiver's thread. Fixes: PYSIDE-1354 Change-Id: I85926efeab157e47ec42a830fda024d299807786 Reviewed-by: Christian Tismer --- sources/pyside2/PySide2/glue/qtcore.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sources/pyside2/PySide2/glue') diff --git a/sources/pyside2/PySide2/glue/qtcore.cpp b/sources/pyside2/PySide2/glue/qtcore.cpp index 6b23a9b79..306a2239c 100644 --- a/sources/pyside2/PySide2/glue/qtcore.cpp +++ b/sources/pyside2/PySide2/glue/qtcore.cpp @@ -374,9 +374,15 @@ static bool getReceiver(QObject *source, const char *signal, PyObject *callback, usingGlobalReceiver = true; } + const auto receiverThread = *receiver ? (*receiver)->thread() : nullptr; + if (usingGlobalReceiver) { PySide::SignalManager &signalManager = PySide::SignalManager::instance(); *receiver = signalManager.globalReceiver(source, callback); + // PYSIDE-1354: Move the global receiver to the original receivers's thread + // so that autoconnections work correctly. + if (receiverThread && receiverThread != (*receiver)->thread()) + (*receiver)->moveToThread(receiverThread); *callbackSig = PySide::Signal::getCallbackSignature(signal, *receiver, callback, usingGlobalReceiver).toLatin1(); } -- cgit v1.2.3