QT 应用程序关闭某个窗口时,关闭打开的所有其他窗口并退出程序 【转】
2013-09-05 13:57
162 查看
原文:/article/2675396.html#
项目中当关闭主窗口时,需要将同时打开的其他窗口关闭,并退出应用程序,实现方法如下:
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联,将主窗口的属性设置为QWidget::setAttribute(WA_QuitOnClose,true);其他窗口该属性设置为false。
具体可参考qt助手中的解释:
By default,
this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus
QApplication implicitly quits when this signal is emitted.
This feature can be turned off by setting quitOnLastWindowClosed to false.
项目中当关闭主窗口时,需要将同时打开的其他窗口关闭,并退出应用程序,实现方法如下:
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联,将主窗口的属性设置为QWidget::setAttribute(WA_QuitOnClose,true);其他窗口该属性设置为false。
int main(int argc, char *argv[]) { QApplication a(argc, argv); a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); int ret = a.exec(); return ret; }
具体可参考qt助手中的解释:
void QApplication::lastWindowClosed () [signal]
This signal is emitted from QApplication::exec() when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed.By default,
this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus
QApplication implicitly quits when this signal is emitted.
This feature can be turned off by setting quitOnLastWindowClosed to false.
相关文章推荐
- QT 应用程序关闭某个窗口时,关闭打开的所有其他窗口并退出程序
- QT 关闭主窗口时触发关闭所有打开的其他窗口
- QT 关闭主窗口时触发关闭所有打开的其他窗口
- 用QT编写的程序,怎样在申请资源失败后,关闭所有窗口,退出程序?
- 用QT编写的程序,怎样在申请资源失败后,关闭所有窗口,退出程序?
- Android 下Qt 多层窗口关闭时程序退出的问题 解决
- Qt界面关闭主窗口,若其Qdialog弹框没有关闭,程序无法退出
- qt 关闭一个页面,结束应用程序运行,关闭其他窗口
- Qt获取管理员权限、窗口置顶并选中,关闭最后一个窗口时应用程序不退出
- QT 关闭主窗口,触发关闭所有打开的窗口
- QT 窗口关闭 程序进程不退出
- VC/MFC程序开启关闭和打开自己或其他软件,更改窗口类
- Android退出程序的时候把所有界面一起关闭
- 建立控制台程序--获得已经打开的一个窗口的句柄--给这个窗口发送一个关闭命令
- Qt 后台进程开发 子窗口关闭后 主程序退出
- 解决嵌入式QT程序关闭窗口后进程不结束问题
- 解决载入(打开)加壳程序后,OD关闭退出的问题
- C# 查找其他应用程序并打开、显示、隐藏、关闭
- Qt中点击关闭任务栏而不退出程序的实现方法
- QT中关闭应用程序和窗口的函数(quit(),exit()以及close()的区别)