qt中隐藏,关闭和显示之间的区别 [英] Difference between hide, close and show in qt

查看:63
本文介绍了qt中隐藏,关闭和显示之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就内存而言,按钮或任何小部件的隐藏、关闭和显示有什么区别?

What is the difference between hide,close and show of pushbutton or any widget in terms of memory?

如果我不想再次使用小部件,哪个更好?

Which is better if I don't want to use widget again?

推荐答案

首先如@Hayt所说,阅读 文档.

First as said @Hayt, read the documentation.

对于实际答案:

  1. hide()setVisible(false) 相同.
  2. show()setVisible(true) 相同.
  3. close() 尝试通过触发 QCloseEvent 来关闭小部件,如果事件被接受,结果是:

  1. hide() is the same as setVisible(false).
  2. show() is the same as setVisible(true).
  3. close() attempts to close the widget by triggering a QCloseEvent, if the event is accepted the result is:

  1. 与调用 hide() 相同,如果 Qt::WA_DeleteOnClose 属性未在默认小部件上设置.

  1. The same as calling hide() if Qt::WA_DeleteOnClose attribute is not set on the widget which is the default.

如果设置了 Qt::WA_DeleteOnClose,则与调用 deleteLater() 相同.

The same as calling deleteLater() if Qt::WA_DeleteOnClose is set.

在内存方面,这 3 个中的任何一个都不会改变任何东西(除了 close() 如果你已经设置了 Qt::WA_DeleteOnClose).如果您永远不想使用该小部件,最好将其删除:

In term of memory, any of the 3 will not change anything (except for close() if you have set Qt::WA_DeleteOnClose). If you do not want to use the widget ever, the best is to delete it:

delete pointerToMyWidget;

pointerToMyWidget->deleteLater();

第二种形式通常更安全,因为第一种形式可能很危险,具体取决于您在哪里编写.(例如,您在由您删除的小部件发出的信号调用的插槽中删除它).

The second form is generally safer as the 1st one can be dangerous depending on where your write it. (e.g you delete it in a slot called by a signal emitted by the widget you delete).

这篇关于qt中隐藏,关闭和显示之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆