My application exits only by right-clicking the tray icon, and pressing "Quit":
class DialogUIAg(QDialog):
...
self.quitAction = QAction("&Quit", self, triggered=qApp.quit)
The Module below is the application's starting point:
#!/usr/bin/env python
import imgAg_rc
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import appLogger
from runUIAg import *
class Klose:
""" Not sure if i need a Class for it to work"""
def closingStuff(self):
print("bye")
@pyqtSlot()
def noClassMethod():
print("bye-bye")
app = QApplication(sys.argv)
QApplication.setQuitOnLastWindowClosed(False)
k = Klose()
app.connect(app, SIGNAL("aboutToQuit()"), k,SLOT("closingStuff()")) #ERROR
app.connect(app, SIGNAL("aboutToQuit()"), k.closingStuff) # Old-Style
app.connect(app, SIGNAL("aboutToQuit()"), noClassMethod) # Old-Style
app.aboutToQuit.connect(k.closingStuff) # New-Style
app.aboutToQuit.connect(noClassMethod) # New-Style
winUIAg = DialogUIAg()
winUIAg.show()
app.exec_()
My intention is to execute a block of code, when the application is aboutToQuit.
This is the Error i am getting:
$ ./rsAg.py
Traceback (most recent call last):
File "./rsAgent.py", line 20, in <module>
app.connect(app, SIGNAL("aboutToQuit()"), k,SLOT("closingStuff()"))
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'Klose'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'Klose'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'Klose'
I am new to python and Qt and i would appreciate your help.
EDIT:
@pyqtSlot() decorator. Thanks to everyone :-)
The PyQt signal/slot syntax isn't entirely identical to the C++ one.
Try with:
class Klose:
def closingStuff(self):
print("bye")
...
app.connect(app, SIGNAL("aboutToQuit()"), k.closingStuff)
Not sure it is necessary in PyQt, but signals and slots are generally expected to come from/go to QObjects. New-style signals and slots could be of interest if your version of PyQt is recent enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With