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

Error in the execution of an overload signal

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.1
    • PySide
    • None
    • All

    Description

      The overload signals do not work correctly that the following MRE checks:

      import sys
      
      from PySide2.QtCore import (
          QCoreApplication,
          QRunnable,
          QObject,
          QThread,
          QThreadPool,
          Slot,
          Signal,
      )
      
      class WorkerSignals(QObject):
          test_sig = Signal((), (str,), (int,))
          finished = Signal()
      
      
      # Test worker
      class Worker(QRunnable):
          def __init__(self):
              super().__init__()
              self.signals = WorkerSignals()
      
          def run(self):
              print("1. send")
              self.signals.test_sig.emit()
              QThread.sleep(1)
              print("2. send")
              self.signals.test_sig[int].emit(100000)
              QThread.sleep(1)
              print("3. send")
              self.signals.test_sig.emit()
              QThread.sleep(1)
              print("4. send")
              self.signals.test_sig[str].emit("a")
              QThread.sleep(1)
              print("5. send")
              self.signals.test_sig.emit()
              QThread.sleep(1)
              print("6. send")
              self.signals.test_sig[str].emit(10000)
              QThread.sleep(1)
              print("7. send")
              self.signals.test_sig.emit()
              QThread.sleep(1)
              self.signals.finished.emit()
      
      
      class Receiver(QObject):
          def __init__(self):
              super().__init__()
              self.threadpool = QThreadPool()
      
          def run_test(self):
              worker = Worker()
              worker.signals.test_sig.connect(self.test_func)
              worker.signals.test_sig[int].connect(self.test_func)
              worker.signals.test_sig[str].connect(self.test_func)
              worker.signals.finished.connect(QCoreApplication.quit)
              self.threadpool.start(worker)
      
          @Slot()
          @Slot(int)
          @Slot(str)
          def test_func(self, arg=None):
              print("receive:", arg, type(arg))
      
      
      if __name__ == "__main__":
          app = QCoreApplication(sys.argv)
          receiver = Receiver()
          receiver.run_test()
          sys.exit(app.exec_())
      

      Output:

      1. send
      2. send
      receive: 100000 <class 'int'>
      3. send
      4. send
      receive: a <class 'str'>
      receive: a <class 'str'>
      5. send
      6. send
      receive: 10000 <class 'int'>
      7. send
      

      If the same logic is implemented with pyqt5(changing Signal with pyqtSignal and Slot with pyqtSlot), the expected behavior is obtained:

      1. send
      receive: None <class 'NoneType'>
      2. send
      receive: 100000 <class 'int'>
      3. send
      receive: None <class 'NoneType'>
      4. send
      receive: a <class 'str'>
      5. send
      receive: None <class 'NoneType'>
      6. send
      receive: 10000 <class 'int'>
      7. send
      receive: None <class 'NoneType'>
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            eyllanesc Edwin Christian Yllanes Cucho
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes