Alex Chudinov
Alex Chudinov

Reputation: 724

How to delete QWidget after QMdiSubWindow was closed

I have a pointer of QWidget subclass:

QWidget * form;

Next I put the instance of the subclass as an internal widget of QMdiSubWindow:

QMdiSubWindow * w = mdiArea->addSubWindow(form);

How to make sure that the object form is deleted when the MDI subwindow w is closed?

Upvotes: 0

Views: 896

Answers (1)

ixSci
ixSci

Reputation: 13708

According to the documentation you must set the Qt::WA_DeleteOnClose flag on the subwindow so it will be automatically deleted after it is closed.

Back to your actual question: when you call addSubWindow it calls setWidget internally. After that step the passed widget's parent is the QMdiSubWindow object on which the call was made. Hence, after that object gets deleted it will also delete all its children, including the said widget, as [almost] any dutiful Qt object does.

Upvotes: 2

Related Questions