qt中隐藏,关闭和显示之间的区别 [英] Difference between hide, close and show in 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.
对于实际答案:
hide()
与setVisible(false)
相同.show()
与setVisible(true)
相同.close()
尝试通过触发QCloseEvent
来关闭小部件,如果事件被接受,结果是:
hide()
is the same assetVisible(false)
.show()
is the same assetVisible(true)
.close()
attempts to close the widget by triggering aQCloseEvent
, if the event is accepted the result is:
与调用
hide()
相同,如果Qt::WA_DeleteOnClose
属性未在默认小部件上设置.
The same as calling
hide()
ifQt::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屋!