QT 关闭主窗口时触发关闭所有打开的其他窗口

本文介绍了如何在QT中实现当主窗口关闭时,强制关闭所有其他打开的窗口并退出程序。主要涉及QApplication::lastWindowClosed信号、Qt::WA_QuitOnClose属性的使用,以及通过设置窗口属性来确保程序正确退出的技巧。
摘要由CSDN通过智能技术生成
  总结了一下网上的资料,感觉有点奇怪,自己实现的一个版本奉上.
1.main函数里设置参数,最后一个窗口关闭时关闭程序.
app.setQuitOnLastWindowClosed(true);

QT助手上这么写
quitOnLastWindowClosed : bool
This property holds whether the application implicitly quits when the last window is closed.

The default is true.

If this property is true, the applications quits 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 for sub-windows. Refer to Qt::WindowType for a detailed list of Qt::Window objects.

Access functions:

bool quitOnLastWindowClosed ()
void setQuitOnLastWindowClosed ( bool quit )

有些人是用的信号/槽实现的
在main函数中将QApplication::lastWindowClosed()信号和QApplication::quit()槽函数相关联
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );

void QApplication::lastWindowClosed () [signal]  后面有QT助手的解释,

明显没有我的方法简单方便
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值