Close all external window


#1

Hi Guys,

 

What would be the cleanest way to close all external window before closing the main window ?

 

So far I'm doing this


  while (juce::TopLevelWindow::getNumTopLevelWindows() > 1)
  {
    delete juce::TopLevelWindow::getTopLevelWindow(1);
  }

but was wondering if this is the right way to do it.

 

Thanks,


#2

Depends what the windows are, and who owns them!

I find it's best to keep ScopedPointers to any open windows, so they disappear automatically when no longer needed.


#3

Those are external windows that runs alongside the main. You can pop out some component and as many as you like.

They handle their own lifetime (closeButtonPressed call delete this) but still I want that they don't survive the main one.

So I'm not a huge fan of the ScopedPointers thingy in that case as it would mean forwarding to this in the closeButtonPressed complexifying the code a lot.

 


#4

I also sometimes use a WeakReference to floating windows that may be deleted elsewhere.

What you've written above is definitely not safe if e.g. a PopupMenu or AlertBox or some other owned window happens to be on-screen.


#5

I see.

Well, I'll do it the long way then.

 

Thanks !