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

When emitting a dictionary using a Signal, if the dictionary keys are integers, the dictionary received in the Slot function is empty.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.2
    • PySide
    • None
    • Python 3.10.6
    • Windows

    Description

      Description:

      When emitting a dictionary from a QThread using a Signal, if the dictionary keys are integers, the dictionary received in the Slot function is empty.

      MRE:

      Using KEY_A = 1 will cause the dictionary received by the Slot method to be empty ({}) whereas it will be as expected when KEY_A="A"

      from PySide6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
      from PySide6.QtCore import QThread, Signal, Slot
      from time import sleep
      import random
      
      KEY_A = 1
      KEY_A = "A"
      KEY_B = "B"
      
      class EmitterThread(QThread):
          dict_signal = Signal(dict)
             
          def run(self):
              while True:
                  random_dictionary =
      
      {                 KEY_A: str(random.randint(1,10)),                 KEY_B: str(random.randint(1,10)),                                  }
      
                  self.dict_signal.emit(random_dictionary)
                  print(f"Emitted dictionary is \{random_dictionary}")
                  sleep(1)
      
      class Widget(QWidget):
          def _{_}init{_}_(self):
              super()._{_}init{_}_()
      
              self.label = QLabel()
              layout = QVBoxLayout()
              layout.addWidget(self.label)
              self.setLayout(layout)
      
              self.emitter = EmitterThread()
              self.emitter.dict_signal.connect(self.update_label)
              self.emitter.start()
             
          @Slot(dict) 
          def update_label(self, value):
              print(f"Received dictionary is \{value}")
              self.label.setText(f"\{KEY_A}: {value[KEY_A]}     \{KEY_B}: {value[KEY_B]}")
      
      app = QApplication([])
      widget = Widget()
      widget.show()
      
      app.exec()
      

      Attachments

        1. pyside2406_diag.diff
          6 kB
        2. pyside2406_log.txt
          0.6 kB
        3. pyside2406_pyqt.py
          1 kB
        4. pyside2406.py
          2 kB
        5. qt_bug_test.py
          1 kB

        Issue Links

          For Gerrit Dashboard: PYSIDE-2406
          # Subject Branch Project Status CR V

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              mac_prible Mac Prible
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change