QT 应用程序关闭某个窗口时,关闭打开的所有其他窗口并退出程序
2015-11-18 21:48
801 查看
项目中当关闭主窗口时,需要将同时打开的其他窗口关闭,并退出应用程序,实现方法如下:
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联,将主窗口的属性设置为QWidget::setAttribute(WA_QuitOnClose,true);其他窗口该属性设置为false。
[cpp] view
plaincopy
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助手中的解释:
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.
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联,将主窗口的属性设置为QWidget::setAttribute(WA_QuitOnClose,true);其他窗口该属性设置为false。
[cpp] view
plaincopy
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) withthe 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应用程序的发布 exe文件图标设置
- Qt入门-提示、警告、错误、询问、关于对话框
- Qt之操作数据库(SQLite)
- QT 使用全局变量的方法
- qtcreator 程序出现Failed to load platform plugin “windows”的错误
- it could not find or load the Qt platform plugin "windows"
- 我的QT5学习之路(三)——模板库、工具类和控件(中)
- 命令行执行Qt程序
- 命令行执行Qt程序
- Qt程序启动画面播放(gif与swf两种动画格式) - 路上的脚印
- QTCreator项目转移到VS项目步骤、中文乱码解决方案
- 老李分享:qtp自动化测试框架赏析-关键字自动化测试框架(二)
- QT QTableWidget 用法总结
- ubuntu 下在应用程序列表中创建QTCREATOR快捷图标
- Qt---在QLabel上实现系统时间
- Ⅰ.2.6.6 如何测试Graphics Views、Graphics Scenes 和 Graphics Items (Qt 4)
- Ⅰ.2.6.5 如何测试QAction、QMenu、以及QMenuBar(Qt 4)
- Qt ini配置文件读写
- Qt的进度条设置
- 在Ubuntu 10.04中文版下Qt编程,使用unixODBC和FreeTDS连接MS SQL Server 2005,并且中文不出现乱码的方法