Popup window distructor not being called

10 views
Skip to first unread message

david allen

unread,
Nov 24, 2020, 12:31:11 PM11/24/20
to fltk.general
My impression is that clicking X in the title bar executes the window's destructor, but that does not seem to be the case for a popup window. In the attached demo the intent is for clicking the X has the same effect as clicking the close button. It appears that the destructor is never called.

I use a recent linus mint and fltk 1.4.

close-popup.cpp

Gonzalo Garramuño

unread,
Nov 24, 2020, 12:40:01 PM11/24/20
to fltkg...@googlegroups.com

El 24/11/20 a las 14:31, david allen escribió:
> My impression is that clicking X in the title bar executes the
> window's destructor, but that does not seem to be the case for a popup
> window. In the attached demo the intent is for clicking the X has the
> same effect as clicking the close button. It appears that the
> destructor is never called.
>
Indeed.  That seems to be the case.  You can fix it by attaching the
callback to window instead, like:


PopUPWin::PopUPWin(int x, int y, int w, int h, const char* label):
                        Fl_Double_Window(x, y, w, h, label)
  {
  hide();
  set_modal();
  show();
  begin();
  button = new Fl_Button(x+10, y+10, 100, 30, "Close");
  end();
  button->callback(close_CB, this);
  callback( close_CB, this );  // new line
  }

david allen

unread,
Nov 24, 2020, 1:25:43 PM11/24/20
to fltk.general
Perfect. Thanks!

Ian MacArthur

unread,
Nov 24, 2020, 5:12:47 PM11/24/20
to fltkg...@googlegroups.com
On 24 Nov 2020, at 17:31, david allen wrote:
>
> My impression is that clicking X in the title bar executes the window's destructor, but that does not seem to be the case for a popup window. In the attached demo the intent is for clicking the X has the same effect as clicking the close button. It appears that the destructor is never called.


Generally speaking, when fltk hides a window, it does not really destroy it per se - and clicking the X in the title bar mostly just hides the window, many of it’s “aspects” are retained... Until the application closes, when the memory is then reaped of course.

That’s not necessarily a bad thing though - pop-up windows are often things like menus or dialogs or etc., that are liable to be re-shown again later, so sort of keeping them around in the background is generally a good idea.

Is there some specific reason you need the destructor to run when the pop-up is removed?


Reply all
Reply to author
Forward
0 new messages