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

QObject.installEventFilter() should prevent gc for the installed object

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.2.3
    • PySide
    • None

    Description

      In following script, the event filter is destroyed by gc when create_label() returns and therefore will not work.

      If the event filter is defined as global, it works as expected.

      It should be better to keep a reference to filter object in installEventFilter().

      import sys
      from PySide6.QtCore import QObject
      from PySide6.QtWidgets import QApplication, QLabel
      
      class Filter(QObject):
          def __del__(self):
              print('del')
      
          def eventFilter(self, obj, event):
              print(event)
              return False
      
      def create_label():
          label = QLabel('hello')
          filter_ = Filter()
          label.installEventFilter(filter_)
          return label
      
      app = QApplication(sys.argv)
      label = create_label()
      label.show()
      sys.exit(app.exec())
      

      Attachments

        Issue Links

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

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              cruiseliu Liu Zhe
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes