Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-3137

Connecting signal/slot in thread causes internal object with QApplication as parent

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.10.0
    • 6.9.0, 6.9.1, 6.8.3
    • PySide
    • None
    • Linux/X11, Windows
    • 992093e0b (dev)

    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

        1. pyside_issue.py
          1 kB
        2. pyside3137.py
          1 kB
        For Gerrit Dashboard: PYSIDE-3137
        # Subject Branch Project Status CR V

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            jorisvr Joris van Rantwijk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes