Search code examples
pythonpysidesignals-slots

Pyside Signal and Slots connect New Method


This code:

self.buttonOk.clicked(self.accept())
self.buttonCancel.clicked(self.reject())

Shows this error:

TypeError: native Qt signal is not callable

How do I connect buttonOk's clicked() signal to accept() Slot?


Solution

  • There are a couple of things wrong with your code.

    Firstly, you need to use the signal's connect() method to make the connection; and secondly, you need to pass in a callable object (i.e. no parens).

    So your code needs to look like this:

    self.buttonOk.clicked.connect(self.accept)
    self.buttonCancel.clicked.connect(self.reject)
    

    An overview of PySide's signal and slot support can be found here.