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

QComboBox.model().item() causes crash when used eventFilter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.10.0
    • 6.8.0.1, 6.9.1
    • PySide
    • None
    • All
    • 8b3b9eccb (dev), 2ef1db2d6 (dev), dd79acd33 (dev)

      I wrote the following test code:

      from PySide6.QtCore import QTimer, QObject
      from PySide6.QtGui import QStandardItemModel
      from PySide6.QtWidgets import QApplication, QComboBox, QVBoxLayout, QWidget
      
      class Watcher(QObject):
          def __init__(self, parent: QWidget):
              super().__init__(parent)
              parent.installEventFilter(self)
      
          def eventFilter(self, watched, event):
              print(watched.objectName(), event)
              return super().eventFilter(watched, event)
      
      class MainWindow(QWidget):
          def __init__(self):
              super().__init__()
              self.setObjectName('-- mainwin --')
              self.combo = QComboBox()
              self.combo.setModel(QStandardItemModel())
              layout = QVBoxLayout()
              layout.addWidget(self.combo)
              self.setLayout(layout)
              self.watcher = Watcher(self)
              self.timer = QTimer(self)
              self.timer.timeout.connect(self.test)
              self.timer.start(100)
      
          def test(self):
              sels = [1,2,3,4,5,6]
              cbx = self.combo
              model = cbx.model()
              cbx.clear()
              cbx.insertItems(0, [f'Item.{no}' for no in sels])
              for (idx, no) in enumerate(sels):
                  itm = model.item(idx)
                  print(f'set model item {idx=} {no=} {itm=}')
      
      if __name__ == "__main__":   
          app = QApplication()    
          window = MainWindow()    
          window.show()    
          app.exec() 

      The error output is shown below:

      -- mainwin -- <PySide6.QtCore.QEvent(QEvent::Paint)>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234656 pos=99,-3 scn=99,-3 gbl=2659,175 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtCore.QEvent(QEvent::Leave)>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234656 pos=95,-7 scn=95,-7 gbl=2655,171 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234671 pos=88,-14 scn=88,-14 gbl=2648,164 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234671 pos=82,-19 scn=82,-19 gbl=2642,159 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234687 pos=74,-23 scn=74,-23 gbl=2634,155 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234687 pos=70,-25 scn=70,-25 gbl=2630,153 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234703 pos=69,-25 scn=69,-25 gbl=2629,153 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234703 pos=69,-26 scn=69,-26 gbl=2629,152 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234734 pos=69,-28 scn=69,-28 gbl=2629,150 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234750 pos=69,-29 scn=69,-29 gbl=2629,149 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      -- mainwin -- <PySide6.QtGui.QMouseEvent(NonClientAreaMouseMove ts=876234750 pos=70,-30 scn=70,-30 gbl=2630,148 dev=QInputDevice(QPointingDevice("core pointer" Mouse id=1 buttonCount=3))>
      set model item idx=0 no=1 itm=<PySide6.QtGui.QStandardItem object at 0x000001BE7186FC00>
      set model item idx=1 no=2 itm=<PySide6.QtGui.QStandardItem object at 0x000001BE718742C0>
      set model item idx=2 no=3 itm=<PySide6.QtGui.QStandardItem object at 0x000001BE71874280>
      set model item idx=3 no=4 itm=<PySide6.QtGui.QStandardItem object at 0x000001BE718743C0>
      set model item idx=4 no=5 itm=<PySide6.QtGui.QStandardItem object at 0x000001BE71874040>
      set model item idx=5 no=6 itm=<PySide6.QtGui.QStandardItem object at 0x000001BE7186EF40>
      -- mainwin -- <PySide6.QtGui.QStandardItem object at 0x000001BE7186FB40>
      Error calling Python override of QObject::eventFilter(): Traceback (most recent call last):
        File "C:\Users\user\jobs\works\mtcs\test\test_cbx_model.py", line 15, in eventFilter
          return super().eventFilter(watched, event)
      TypeError: 'PySide6.QtCore.QObject.eventFilter' called with wrong argument types:
        PySide6.QtCore.QObject.eventFilter(MainWindow, QStandardItem)
      Supported signatures:
        PySide6.QtCore.QObject.eventFilter(watched: PySide6.QtCore.QObject, event: PySide6.QtCore.QEvent, /) 

       

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

            crmaurei Cristian Maureira-Fredes
            magai magai lee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes