[SOLVED] Difference between QWidget::hide() and QWidget::close()
I am little bit confused regarding difference between QWidget::hide() and QWidget::close().
What exactly happens if "I close and show a widget" and "I hide and show a widget"
It's desribed quite clearly in "the documentation":http://qt-project.org/doc/qt-4.8/qwidget.html#close.
::hide() only makes the widget disappear. ::close() can even destroy it in some cases.
close and hide are two different things.
Close is typically done, when you click the cross in the upper right corner. If a widget has the flag delete on close, it will be deleted afterwards.
Hid just makes the widget hidden.
bq. 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.
This is QWidget::close() detail, so default behavior is, whenever the ::close() is called, it simply hides the widget, right.?
hide : we can reuse or display again
close : widget completely close.
[quote author="aekam" date="1366881423"]This is QWidget::close() detail, so default behavior is, whenever the ::close() is called, it simply hides the widget, right.?[/quote]
Read the whole description. The point is: it might just hide the widget on close(), but if your settings in code are different, it might delete it completely, or even close the whole application.
If you need the widget later, use hide() or setVisible(false). If you need to destroy it, do it yourself. close() is to be used with care.
The difference is that when you close the widget, if the Qt::WA_DeleteOnClose flag is set, the widget is deleted and any other data that it stored along with it... If not, the close method is a fancier way to say hide :)
also, if it is the only window open in your application it quits the application... so as sierdzio said:
[quote author="sierdzio" date="1366881775"]
If you need the widget later, use hide() or setVisible(false). If you need to destroy it, do it yourself. close() is to be used with care.[/quote]
Thank you all for information... :)
hide() = close()
hide() != close() + deleteLater()
JonB last edited by
hide() = close()
I don't know why you are replying to a thread last updated a decade ago! But as stated in the answers above,