2

如何在 pyqt4 python 中使用 QApplication.commitData 捕获关闭信号?我想在计算机关闭之前正确关闭程序。

4

1 回答 1

1

您可以尝试连接到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_()
于 2012-07-04T04:11:41.373 回答