如何在 pyqt4 python 中使用 QApplication.commitData 捕获关闭信号?我想在计算机关闭之前正确关闭程序。
请您参考如下方法:
您可以尝试连接到 QApplication.aboutToQuit信号,但正如@Blender 在评论中建议的那样,不能保证您的应用程序会正常关闭。我认为操作系统会尝试很好地关闭每个应用程序。
from PyQt4 import QtCore, QtGui
def shuttingDown():
print "Shutting down"
app = QtGui.QApplication([])
app.aboutToQuit.connect(shuttingDown)
w = QtGui.QWidget()
w.show()
app.exec_()
