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

Details

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

    Description

      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())

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes