andrei_c wrote:
> void add_cb(Fl_Widget *widget, void *p) // function for adding
> {
>   Fl_Button *button = (Fl_Button *) widget;
>   Fl_Value_Input *x = (Fl_Value_Input *) button->parent()->child(2);
>   Fl_Value_Input *y = (Fl_Value_Input *) button->parent()->child(3);
>   Fl_Value_Output *z = (Fl_Value_Output *) button->parent()->child(4);
>   z->value( x->value() + y->value() ); // this is the actual addition
> }

        I wouldn't recommend doing things this way (it's better to
        use an app class or globals) but in add_cb() shouldn't that be:

   Fl_Value_Input *x = (Fl_Value_Input *) button->parent()->child(1);   // <- 1
   Fl_Value_Input *y = (Fl_Value_Input *) button->parent()->child(2);   // <- 2
   Fl_Value_Output *z = (Fl_Value_Output *) button->parent()->child(3); // <- 3

        ..and ditto for the rest.

        I'd suggest peppering in some printf()s to see what the xyz values
        are on creation, and compare those to what you computed in your 
callback.
        eg:

printf("x=%p y=%p z=%p\n", (void*)x, (void*)y, (void*)z);

        When I first put this in your add_cb() callback and in main(), I got
        different results:


x=0x8088108 y=0x8088250 z=0x8088380     <-- main
x=0x8088250 y=0x8088380 z=0x8088418     <-- callback

        ..which showed the widgets were mismatched.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to