Description
When connecting a signal to a slot in a background thread, I get an unexpected error:
QObject: Cannot create children for a parent that is in a different thread.
I do understand that QObject instances may not have a parent with a different thread affinity. But in my case, the error occurs in a spot where I'm not even trying to create a QObject instance. I suspect that PySide internally creates a QObject instance and incorrectly attempts to use the QApplication instance as parent.
I basically just run this code in a background QThread (full example attached). The error occurs during the call to "connect()".
timer = QTimer()
timer.timeout.connect(self.on_timeout)
I suspect this happens because PySide internally creates an instance of SenderSignalDeletionTracker and uses the QApplication instance as parent:
https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/pyside6/libpyside/dynamicslot.cpp#n398
I have not verified that SenderSignalDeletionTracker is the cause; it is just a hypothesis. It is consistent with the fact that the issue disappears if I change my program such that the first signal/slot creation occurs in the main thread.
Attachments
For Gerrit Dashboard: PYSIDE-3137 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
657957,8 | PySide6: Suppress warning when doing first signal connection from a thread | dev | pyside/pyside-setup | Status: MERGED | +2 | +1 |