Solved What's the "Qt Way" for handling cleanup of parentless windows?
-
My application creates some "parentless windows" so that the user can drag them outside the bounds of the main window and can orient the windows in "Z" above or below the main window and the other parentless windows as desired.
But when the user closes the main application window, I'd like all the parentless windows to be cleaned up as well. The only way I've been able to make that work is by keeping pointers to them and closing each on exit. It "works" but it doesn't feel like the right approach.. Is there a better way?
-
@pmh4514
Hi
Have you checked
QApplication::topLevelWidgets()
http://doc.qt.io/qt-5/qapplication.htmllike
void showAllHiddenTopLevelWidgets() { foreach (QWidget *widget, QApplication::topLevelWidgets()) { if (widget->isHidden()) widget->show(); } }
-
Thanks! I knew there would be a "Qt Way"
I also found QApplication::closeAllWindows -
@pmh4514
Even better :) -
@pmh4514 said in What's the "Qt Way" for handling cleanup of parentless windows?:
Thanks! I knew there would be a "Qt Way"
I also found QApplication::closeAllWindowsIf the windows have the attribute WA_DeleteOnClose set, this will also run their destructors. I am not sure whether this attribute is set by default.
-
@Asperamanca, no it's not.