我是靠谱客的博主 可耐灰狼,这篇文章主要介绍程序退出的几种方法,现在分享给大家,希望可以做个参考。

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

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

最后

以上就是可耐灰狼最近收集整理的关于程序退出的几种方法的全部内容,更多相关程序退出内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(160)

评论列表共有 0 条评论

立即
投稿
返回
顶部