On Fri, 25 Jan 2013 09:13:15 -0600
Moses McKnight <[email protected]> wrote:

> void gen_license_cb(Fl_Widget *w, void *ptr)
> {
>       licgen generator;
>       generator.make_window();
>       generator.hub_id_input->type(FL_INT_INPUT);
>       generator.hub_id_input->precision(0);
>       generator.hub_id_input->value(hub_id);
>       generator.window->show();
> }
> 
> I think the object is being deleted after the show() even though the 
> window is still there and active.
> 
> What is the best way to keep the object around until the window is closed?

Since I now use mainly Python, my C++ is a bit rusty, but...

Other than a complete reorganisation of the code to move generator
to global scope in order to avoid its destruction and memory reuse
at the end of the gen_license_cb() scope, you could possibly use
"static licgen generator;" instead, or do something like:

void gen_license_cb(Fl_Widget *w, void *ptr)
{
        static licgen* pGenerator = 0;
        if (pGenerator == 0) {
                pGenerator = new licgen();
        }
        pGenerator->make_window();
        pGenerator->hub_id_input->type(FL_INT_INPUT);
        pGenerator->hub_id_input->precision(0);
        pGenerator->hub_id_input->value(hub_id);
        pGenerator->window->show();
}

But of course there is no way to release the resources used by the
"static licgen generator;" in the first case, nor any direct way of
calling "delete pGenerator;" in the second.

D.


This message and any attachments are intended for the use of the addressee or 
addressees only. The unauthorised disclosure, use, dissemination or copying 
(either in whole or in part) of its content is not permitted. If you received 
this message in error, please notify the sender and delete it from your system. 
Emails can be altered and their integrity cannot be guaranteed by the sender.

Please consider the environment before printing this email.

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to