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

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Invalid
    • Affects Version/s: 1.1.2, 1.2.0, dev
    • Fix Version/s: dev
    • Component/s: PySide
    • Labels:
    • Environment:
      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

            Assignee:
            crmaurei Cristian Maureira-Fredes
            Reporter:
            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