setQuitOnLastWindowClosed

首先看函数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

这里只是说明其略微的不同
---------------------
作者:seanyxie
来源:CSDN
原文:https://blog.csdn.net/seanyxie/article/details/5805631?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2018-10-16 11:31  赵二冬  阅读(2811)  评论(0编辑  收藏  举报