PDA

View Full Version : Closing all of the mainWindow's child dialogs



JPNaude
2nd October 2008, 10:47
Hi

I'm trying to find a way to delete all of the opened child windows (separate dialogs) of my mainWindow. Is this possible. I've looked at the destroy function of the QWidget base class, but it seems like this will destroy all the qwidgets of the mainWindow as well. Is there an easy way to do this? Or is it necessary to do some sort of recursive run through all the children?

Thanks
Jaco

jpn
2nd October 2008, 11:06
All you need to do is to pass the main window as parent to the dialogs. When the main window is destructed (Qt::WA_DeleteOnClose might become handy), all its children are automatically destructed as well.

JPNaude
2nd October 2008, 12:23
Thanks for the reply.

I'm aware of the solution you posted. However I want to be able to close all the opened windows without having to close the main window.

Thanks
Jaco

jpn
2nd October 2008, 12:55
See QApplication::topLevelWidgets() or QApplication::closeAllWindows().

JPNaude
2nd October 2008, 14:18
Thank you very much. This is exactly what I was looking for.

Jaco