Qt中的窗口属性

Qt::WA_DeleteOnClose

在初始化窗口时设置:

setAttribute(Qt::WA_DeleteOnClose);

表示当窗口调用close()函数,之后发送closeEvent事件,如果窗口接受closeEvent事件,窗口会调用hide隐藏窗口,并销毁该窗口,

如果widget不接受关闭事件,那么窗口将什么也不做。

如果在程序中需要通过 new 的方式创建一个窗口,可以给该窗口设置 Qt::WA_DeleteOnClose属性。

这样在关闭这个窗口时Qt能够自动回收该窗口所占用的资源,这样不用特意析构这个窗口类就能够及时回收无效的资源,有用利于节约内存空间。

参考:前行中的小猪:http://blog.csdn.net/goforwardtostep/article/details/53647146

Qt::WA_QuitOnClose

 
Qt::WA_QuitOnClose
 
Makes Qt quit the application when the last widget with the attribute set has accepted closeEvent(). 
This behavior can be modified with the QApplication::quitOnLastWindowClosed property. By default this attribute is set for all widgets of type Qt::Window.
 
qt退出应用程序当最近接受closeEvent事件并设置了此属性的窗口,这个行为可被QApplication::quitOnLastWindowClosed属性更改,

 
 
注:可通过此属性设置当主窗口退出时,此应用程序的其他正在打开的窗口也同时退出。
 
在主窗口初始化设置 

setAttribute(Qt::WA_QuitOnClose, true);
其他窗口初始化中设置:

setAttribute(Qt::WA_QuitOnClose, false);


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值