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

QObject.connect silently fails when connected to method of instance not stored in variable

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • 6.0
    • 1.1.2, 1.2.0
    • PySide
    • Python 2.7.5; Windows 7 32-bit | Python 2.7.3; Ubuntu 13.04 32-bit

    Description

      Example:

      from PySide.QtCore import *
      from PySide.QtGui import *
      
      class Connector(object):
          def __init__(self):
              button.clicked.connect(self.slot)
      
          def slot(self):
              print 'Clicked'
      
      app = QApplication(())
      button = QPushButton('Press me')
      Connector()
      button.show()
      app.exec_()
      

      Wrapping self.slot in a function surprisingly causes this example to work, albeit in an ugly way:

      from PySide.QtCore import *
      from PySide.QtGui import *
      
      class Connector(object):
          def __init__(self):
              # `self.slot` -> `lambda: self.slot()`
              button.clicked.connect(lambda: self.slot())
      
          def slot(self):
              print 'Clicked'
      
      app = QApplication(())
      button = QPushButton('Press me')
      Connector()
      button.show()
      app.exec_()
      

      This problem can be avoided altogether by assigning the connector instance to a variable (e.g. connector = Connector(), but it shouldn't be necessary to do this.

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            dk D K
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes