I'd do it this way (below).
Didn't try to debug your code, as problem might be elsewhere in code.
In your callback, instead of using o->userdata(), use 'v', as that's
your userdata in a simple form.
To debug your segfaults, print the value of 'pUI' and tmpfiltermatrix[i]
before atof() line, since one of them is probably NULL or wild.
Yes your callback needs to be static, but as shown below, you can
have static callback invoke non-static callback by dereferencing your UI*
so that your non-static callback can then have free reign over your class.
When you run the following, the Fl_Input's will show the data[] array's values,
and when you make changes to any field, the data[] array is modified, and entire
data array printed to stdout so that you can see it change.
* * *
#include <stdio.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/fl_message.H>
//
// Demonstrate using Fl_Input's to manage an array
// erco 10/09/05
//
class MyUI : public Fl_Window {
int data[10]; // integer data to be managed
Fl_Input *in[10]; // array of Fl_Input widgets
// Nonstatic callback
void HandleInput() {
for ( int i=0; i<10; i++ ) {
if ( sscanf(in[i]->value(), "%d", &data[i]) != 1 ) { //
assign input string to data array element
fl_message("The string '%s' for input #%d is not an integer",
in[i]->value(), i);
}
// Print modified data array to screen so we can see it
printf("data[%d] is now %d\n", i, data[i]);
}
printf("---\n");
}
// Raw callback
static void HandleInput_CB(Fl_Widget *w, void *v) {
MyUI *ui = (MyUI*)v; // userdata is pointer to class
ui->HandleInput(); // invoke non-static callback
}
public:
// CONSTRUCTOR
MyUI(int W,int H) : Fl_Window(W,H) {
// initialize array, create input widgets and assign each an item in
array
char label[80];
char val[80];
for ( int i=0; i<10; i++ ) {
data[i] = i * 100; // initialize
data array to some values
sprintf(val, "%d", data[i]); // string
version of data value for Fl_Input
sprintf(label, "Item %d:", i); // label of
Fl_Input that includes index#
in[i] = new Fl_Input(100,10+i*30,100,25); // create input
widget, save
in[i]->copy_label(label); // label it
with item# for clarity
in[i]->callback(HandleInput_CB, (void*)this); // assign
callback too data element
in[i]->value(val); // initialize
input field to data[]'s value
in[i]->when(FL_WHEN_CHANGED);
}
}
};
int main() {
MyUI win(300, 500);
win.show();
return(Fl::run());
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk