首页QT › 程序退出的几种方法

程序退出的几种方法

首先看函数QApplication::setQuitOnLastWindowClosed(bool) ,该函数的作用是
This property holds whether the application implicitly quits when the last window is closed.
The default is true

即控制着当最后一个可视的窗口退出时候,程序是否退出,默认是是的
如果使用app.setQuitOnLastWindowClosed(false);然后当该出窗口close以后,ps -e查看,我们发现应用程序仍旧在运行中

所以当此时,如果所有的窗口都响应了close(),那么application就退出了,

如果窗口关闭,就返回TRUE,否则返回FALSE

首先给widget发送一个QCloseEvent,如果widget接受了event,就hide,如果忽略,就什么事情都不做,默认的是接受

The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed.

当最后一个可视窗口退出时候,信号QApplication::lastWindowClosed() 被发射,然后quit

当然也可以在某一个时刻,直接调用quit()方法来退出application

这里只是说明其略微的不同

发表评论