aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pyside.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-07-08 14:33:03 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-07-08 15:55:34 +0200
commit94a36e5b247081602f74590def7a54c4d9fc7ea8 (patch)
tree5b361a5f58461b31f0d6ae5d892c17c88db3c504 /sources/pyside6/libpyside/pyside.cpp
parent7e45fec9047364cb003e38562edf81ffc18eea1d (diff)
Fix assert when retrieving wrapper from different thread
Check if the thread matches before calling QObject::setProperty(), fixing: ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 0x0x1e2bd40. Receiver '' (of type 'QDBusConnectionInterface') was created in thread 0x0x7f54b3ce16e0", file qtbase/src/corelib/kernel/qcoreapplication.cpp, line 554 Task-number: PYSIDE-1570 Change-Id: Ib10984a03606bf2cf4dddb0dbd9dfaed3e4d09fe Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/libpyside/pyside.cpp')
-rw-r--r--sources/pyside6/libpyside/pyside.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/sources/pyside6/libpyside/pyside.cpp b/sources/pyside6/libpyside/pyside.cpp
index 2026fee53..af181810a 100644
--- a/sources/pyside6/libpyside/pyside.cpp
+++ b/sources/pyside6/libpyside/pyside.cpp
@@ -68,6 +68,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QSharedPointer>
#include <QtCore/QStack>
+#include <QtCore/QThread>
#include <algorithm>
#include <cstring>
@@ -463,8 +464,10 @@ PyObject *getWrapperForQObject(QObject *cppSelf, SbkObjectType *sbk_type)
// set and check if it's created after the set call
QVariant existing = cppSelf->property(invalidatePropertyName);
if (!existing.isValid()) {
- QSharedPointer<any_t> shared_with_del(reinterpret_cast<any_t *>(cppSelf), invalidatePtr);
- cppSelf->setProperty(invalidatePropertyName, QVariant::fromValue(shared_with_del));
+ if (cppSelf->thread() == QThread::currentThread()) {
+ QSharedPointer<any_t> shared_with_del(reinterpret_cast<any_t *>(cppSelf), invalidatePtr);
+ cppSelf->setProperty(invalidatePropertyName, QVariant::fromValue(shared_with_del));
+ }
pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppSelf));
if (pyOut) {
Py_INCREF(pyOut);