Ok, I think I figured it out.  The way I create the window is like this 
in a menu callback function:

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?


On 01/25/2013 08:58 AM, Moses McKnight wrote:
> On 01/25/2013 03:27 AM, Ian MacArthur wrote:
>>
>> On 25 Jan 2013, at 04:56, Moses McKnight wrote:
>>
>>> I'm using the latest svn of fltk 1.3, and I have a simple window
>>> with an Fl_Output.  When I call the value(const char*) function
>>> with a string I get a segmentation fault, and running it in the
>>> debugger shows it happens in the Fl_Widget::clear_changed()
>>> function, called at the beginning of the
>>> Fl_Input_::static_value(const char* str, int len) function.
>>>
>>> Any idea why this might be happening?  I am using a number of
>>> Fl_Output in other windows in this same application without any
>>> problems.
>>
>>
>> Without seeing more of your code, it's hard to say: a common reason
>> for this sort of thing is that something (perhaps the string?) has
>> been declared stack-automatic in some function, and has fallen out of
>> scope before it is used... Does that sound likely here?
>
> No, because here is my call:  info_output->value("Testing");
>
> I've done a little more testing and figured out that I can set the value
> from outside the class, but not from a function in the class.
> I also get a seg fault when I click the "Close" button, which is similar
> I think because it calls a function on a object in the class.
>
> I've included some of the code below.  It is generated by fluid and the
> same kind of thing is working in other windows in the same application.
> The generate_license() function is in a separate file so I don't have to
> change the fluid generated files, and that is where I call
> info_output->value("Testing");
>
>
> Here is my header file:
>
> // generated by Fast Light User Interface Designer (fluid) version 1.0302
>
> #ifndef licensegen_h
> #define licensegen_h
> #include <FL/Fl.H>
> #include <FL/Fl_Double_Window.H>
> #include <FL/Fl_Value_Input.H>
> #include <FL/Fl_Output.H>
> #include <FL/Fl_Button.H>
>
> class licgen {
> public:
>     void generate_license();
>     Fl_Double_Window* make_window();
>     Fl_Double_Window *window;
>     Fl_Value_Input *hub_id_input;
>     Fl_Output *info_output;
> private:
>     inline void cb_Generate_i(Fl_Button*, void*);
>     static void cb_Generate(Fl_Button*, void*);
>     inline void cb_Close_i(Fl_Button*, void*);
>     static void cb_Close(Fl_Button*, void*);
> };
> #endif
>
>
> And here is the main code:
>
> // generated by Fast Light User Interface Designer (fluid) version 1.0302
>
> #include "licensegen.h"
>
> void licgen::cb_Generate_i(Fl_Button*, void*) {
>     generate_license();
> }
> void licgen::cb_Generate(Fl_Button* o, void* v) {
>     ((licgen*)(o->parent()->user_data()))->cb_Generate_i(o,v);
> }
>
> void licgen::cb_Close_i(Fl_Button*, void*) {
>     window->hide();
> }
> void licgen::cb_Close(Fl_Button* o, void* v) {
>     ((licgen*)(o->parent()->user_data()))->cb_Close_i(o,v);
> }
>
> Fl_Double_Window* licgen::make_window() {
>     { window = new Fl_Double_Window(435, 130, "License Generator");
>       window->labelsize(12);
>       window->user_data((void*)(this));
>       { hub_id_input = new Fl_Value_Input(5, 30, 275, 25, "ID#");
>         hub_id_input->labelsize(12);
>         hub_id_input->textsize(12);
>         hub_id_input->align(Fl_Align(FL_ALIGN_TOP_LEFT));
>       } // Fl_Value_Input* hub_id_input
>       { info_output = new Fl_Output(5, 63, 420, 25);
>         info_output->color(FL_BACKGROUND_COLOR);
>         info_output->labelsize(12);
>         info_output->textsize(12);
>         info_output->align(Fl_Align(FL_ALIGN_TOP_LEFT));
>       } // Fl_Output* info_output
>       { Fl_Button* o = new Fl_Button(290, 30, 135, 25, "Generate
> License...");
>         o->labelsize(12);
>         o->callback((Fl_Callback*)cb_Generate);
>       } // Fl_Button* o
>       { Fl_Button* o = new Fl_Button(180, 98, 80, 25, "Close");
>         o->labelsize(12);
>         o->callback((Fl_Callback*)cb_Close);
>       } // Fl_Button* o
>       window->end();
>     } // Fl_Double_Window* window
>     return window;
> }
>
> _______________________________________________
> fltk mailing list
> fltk@easysw.com
> http://lists.easysw.com/mailman/listinfo/fltk
>

_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to