简体   繁体   中英

how to catch shutdown signal in pyqt4 python?

How to catch shutdown signal using QApplication.commitData in pyqt4 python? I want to properly close the program before the computer turns off.

You can try connecting to the QApplication.aboutToQuit signal, but as @Blender suggests in comments, there is no guarantee that your application will be shut down nicely. I would think that the OS would try to nicely shut down each app.

from PyQt4 import QtCore, QtGui

def shuttingDown():
    print "Shutting down"

app = QtGui.QApplication([])
app.aboutToQuit.connect(shuttingDown)
w = QtGui.QWidget()
w.show()
app.exec_()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM