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

Emitting dicts in Signals does not work with ints as keys

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Not Evaluated Not Evaluated
    • None
    • 6.6.2
    • PySide
    • None
    • macOS

      The following example shows a problem when emitting dictionaries in Signals. It works perfectly when the keys of the dictionary do not contain any ints. The moment one key is of type integer, the dictionary is empty.

      I’d expect this to work, or, if it cannot work, at least raise some exception.

      from PySide6.QtCore import Signal, Slot, QObject
      from PySide6.QtWidgets import (
          QApplication,
          QPushButton,
          QMainWindow,
          QHBoxLayout,
          QWidget,
      )
      import sys
      
      
      class Button(QPushButton):
          signal = Signal(dict, name="signal")
      
          def __init__(self) -> None:
              super().__init__()
              self.clicked.connect(self.on_clicked)
      
          @Slot(name="on_clicked")
          def on_clicked(self):
              self.signal.emit({192: "bar"})
              self.signal.emit({"192": "bar"})
              self.signal.emit({"192": "foo", 192: "bar"})
      
      
      class Receiver(QObject):
          @Slot(dict, name="on_clicked")
          def on_signal(self, data: dict) -> None:
              print(f"Received {data}")
      
      
      app = QApplication(sys.argv)
      
      window = QMainWindow()
      window.setCentralWidget(QWidget())
      window.centralWidget().setLayout(QHBoxLayout())
      button = Button()
      receiver = Receiver()
      button.signal.connect(receiver.on_signal)
      window.centralWidget().layout().addWidget(button)
      window.show()
      sys.exit(app.exec())

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

            crmaurei Cristian Maureira-Fredes
            tilmankrummeck Tilman Krummeck
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes