I would like to have two different methods for quitting the app:
The event where "X" is pressed is connected to a closeEvent function:
def closeEvent(self, event):
message = QtGui.QMessageBox.question(self, "quit", "Do you really want to quit?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if message == QtGui.QMessageBox.Yes:
event.accept()
else:
event.ignore()
Is there a way to connect the push button's clicked event to go through the exact same function in order to quit? I've tried:
self.quit.clicked.connect(self.closeEvent(QtCore.QCoreApplication.quit))
but as soon as I run the GUI, the first thing that pops up is the message box.
What am I doing wrong and how could I fix it?
EDIT 1:
I've also tried
self.quit.clicked.connect(self.closeEvent(QtCore.QCoreApplication.instance().quit))
but it doesn't work either.
Just connect to the window's close
slot:
self.quit.clicked.connect(self.close)
Calling close()
posts a close-event, which will subsequently be delivered to the window's closeEvent
handler.