FLTK logo

Re: [fltk.general] Re: Newbie: question about destruction of FLTK ojbects

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.general  ]
 
[ Previous Message ] [ New Message | Reply ] [ Next Message ]

Re: Re: Newbie: question about destruction of FLTK ojbects "'Albrecht Schlosser' via fltk.general" 14:08 Sep 27  
 
On 9/27/26 15:40 S ET wrote:
I got to deleting the main window in a handler, may be it's not the optimal way though:

// ----------------------------------------------------------------------------------------------
static int OnMainWindowEvent(Fl_Widget * w, void * p)
{
  int ev = Fl::event();
 
  switch (ev)
  {
    case FL_CLOSE:
      delete w;
      return 0; // 0 or 1 ?
    default:
      std::cout << "Main window event: " << ev << std::endl;
      break;
  }
 
  return 1;
}
// ----------------------------------------------------------------------------------------------

Unfortunately you didn't write how you established (registered) this "handler". Its signature looks like a callback of a widget. Since you are using `delete w` I assume that it's established like:

  cw->callback(OnMainWindowEvent, ...);

Hence this would call the callback when the window is closed by its close button. There's no need to check for the recent event by calling `Fl::event();` - did you ever see the output of `"Main window event: " << ev << ...` ?

However, a callback would be a `void` function, i.e. it would return nothing. There are other real handler() methods which are called from event handling that must return 0 or 1, depending on whether you used (consumed) the event. But these can only be defined if you subclass another widget class.

Last but not least, this handler would delete the window object, which is - as Ian and I said - not necessary, but it doesn't remove your directory, does it?

I am happy to read the many more options you have listed;

and to note the reactivity of the forum.

So many more subtleties to discover yet.

Thank you all and regards.

Welcome. There is indeed much more to discover. If you want to learn more about FLTK, reading the first chapters of the documentation, which are kinda tutorials, is strongly recommended. There are also a lot of test and example programs bundled with the FLTK library in these folders:
  • /examples/ : these attempt to provide short programs with good coding practices to new users
  • /test/ : all kinds of test and demo programs to test the FLTK library itself. The code in these programs works but may not be the recommended practice for user programs. It's a valuable resource for learning FLTK though.

Have fun with FLTK!


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkgeneral/1e559ccc-79fb-4ad1-9c31-49f0f09e4d09%40aljus.de.
[ Direct Link to Message ]
 
     
[ Previous Message ] [ New Message | Reply ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.