Closing dialog windows on shutdown


#1

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.setOwned(se);
launchOptions.content->setSize(600, 580);
launchOptions.dialogBackgroundColour = LookAndFeel::getDefaultLookAndFeel().findColour(ResizableWindow::backgroundColourId);

launchOptions.runModal();

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

Any hint is appreciated.

Regards
Matthias


#2

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.


#3

Ok, thank you.

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


#4

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


#5

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