首页| 论坛| 消息

标题:【提问】QWidget的close()和hide()有什么区别?
作者:lj_0212
日期:2006-03-02 18:22
内容:

如题。
根据文档,调用close()时,也是将部件隐藏。实际写代码测试,也是如此。
在写多窗口程序时,当前不显示的部件只调用close()就可以了么?
有哪位兄弟有这方面经验,还望赐教!


#1 [zccmin 03-02 18:54]
实际上区别还是很大的。如果有个组件,你先隐藏,然后在需要显示。你就会发现区别了。
如果用的hide(),你只要再用show()就能显示。可是用的close(),则必须重新生成该对象。
#2 [lj_0212 03-02 19:19]
先感谢一下!
我马上测试一下。
再问几个问题?
那是否意味着已经不需要显示的窗口部件只调用一下close()就可以了?这样不会占用内存空间么?不会因为这样做造成溢出吧?
#3 [XChinux 03-02 19:22]
Qt Reference中说的:
bool QWidget::close ()
Closes this widget. Returns true if the widget was closed; otherwise returns false.
First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.
If the widget has the Qt::WA_DeleteOnClose flag, the widget is also deleted. A close events is delivered to the widget no matter if the widget is visible or not.
The QApplication::lastWindowClosed() signal is emitted 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.
#4 [lj_0212 03-02 19:39]
这是4.X的文档吧,Qt::WA_DeleteOnClose 这个flag一直都有么?
#5 [nanhu_007 03-05 07:27]
下面是引用lj_0212于2006-03-02 11:19发表的:
先感谢一下!
我马上测试一下。
再问几个问题?
那是否意味着已经不需要显示的窗口部件只调用一下close()就可以了?这样不会占用内存空间么?不会因为这样做造成溢出吧?
调用close()会把对象给析构掉。
“不会因为这样做造成溢出吧?”不知道是什么意思????
我猜应该是会不会内存泄漏吧?
那是看你的程序是什么写的了

<< 1 2 >> (1/2)

回复 发表
主题 版块