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

Invalid parameter type to Signal.emit results in crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.3.0
    • PySide
    • None
    • All

    Description

      If you mistakenly pass a list of strings to a Signal(QObject), Python will crash.

      The following PySide6 code snippit will result in a crash. I would expect an exception to be thrown instead of a crash.

      from typing import Optional
      from PySide6.QtCore import QCoreApplication, QObject, QStringListModel, Signal, QTimer
      from PySide6.QtGui import QColor
      import sys
      import signal
      
      class MyData(QObject):
          _color_names: QStringListModel = QStringListModel()
      
          _counter = 0
          color_names_changed = Signal(QObject)
      
          def __init__(self, parent: Optional[QObject] = None) -> None:
              super().__init__(parent)
              self._color_names.setStringList(QColor.colorNames())
              self._timer = QTimer(self)
              self._timer.timeout.connect(self.doEmit)
              self._timer.start(500)
      
          def doEmit(self):
              if self._counter == 5:
                  QCoreApplication.instance().quit()
      
              self.color_names_changed.emit(QColor.colorNames())
              # Above was a mistake, should have been self.color_names_changed.emit(self._color_names)
              self._counter += 1
      
      def main() -> int:
          signal.signal(signal.SIGINT, signal.SIG_DFL)
          app = QCoreApplication(sys.argv)
      
          myData = MyData()
          app.exec()
          return 0
      
      if __name__ == "__main__":
          sys.exit(main())
      

      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
              kkyzivat Keith Kyzivat
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes