Closing dialog windows on shutdown


Hi everybody.

Let’s say I open a dialog window like that:

        DialogWindow::LaunchOptions launchOptions;

SampleEditor* se = new SampleEditor();

launchOptions.dialogTitle = ("Edit samples");
launchOptions.escapeKeyTriggersCloseButton = true;
launchOptions.resizable = false;
launchOptions.useNativeTitleBar = false;
launchOptions.useBottomRightCornerResizer = true;
launchOptions.componentToCentreAround = getParentComponent();
launchOptions.content->setSize(600, 580);
launchOptions.dialogBackgroundColour = LookAndFeel::getDefaultLookAndFeel().findColour(ResizableWindow::backgroundColourId);


How do I properly close that window (and all other probably non modal dialogs) on application shutdown?

Any hint is appreciated.



Start by not using modal loops!

Use launchAsync(), not runModal, because if you quit in the middle of the runModal call, you can get screwed. And all you need to do is keep a pointer e.g. a std::unique_ptr to the window that is returned, and make sure it gets deleted during shutdown.


Ok, thank you.

Any suggestion on how to get the pointer to the window?


If you look at the launchAsync function, you’ll see that it returns the pointer.


Thanks. Works perfectly. I did not notice that the pointer is only being returned by launchAsync and not runModal.