PDA

View Full Version : Window destructors and the destroy method



sterling
25th December 2013, 04:44
When accepting a closeEvent on a parentless window doing a destroy( true, true ) doesn't call the window's destructor.
This can be fixed by explicitly calling the window's destructor in the closeEvent.

Do I need to/should I call the destroy method in the destructor?

If the window has a parent, and I force the window to close by calling the destructor, will the parent be notified of the close?
If not, what do I need to to do to make sure the window is properly removed from the parent's child list?

What documentation addresses this issue?

Radek
25th December 2013, 07:36
Too few info for giving some recommendation. Look at Qt::WA_DeleteOnClose and Qt::WA_QuitOnClose flags. Do not call dtors explicitly, it's an extra bad programming practice. Try to have your dtors called naturally, by your code logic.

If the dtor was not called, the window was not destroyed. It was hidden. Is your main window a dialog or a frame window? How many top level windows do you have?

anda_skoa
25th December 2013, 10:48
When accepting a closeEvent on a parentless window doing a destroy( true, true ) doesn't call the window's destructor.

The destructor calls destroy, so no need to call it yourself.



This can be fixed by explicitly calling the window's destructor in the closeEvent.

As Radek said, if you want a window to be destroyed on close, use the DeleteOnClose attribute.


Do I need to/should I call the destroy method in the destructor?

No, that's what the base implementation already does (as documented for QWidget::destroy())



If the window has a parent, and I force the window to close by calling the destructor, will the parent be notified of the close?

A parent QObject is always notified about a child's deletion. Otherwise it would attempt to delete it again upon its deletion.

Cheers,
_