[Insight-users] fltk callback problem

Karthik Krishnan Karthik.Krishnan at kitware.com
Sun Feb 19 17:42:15 EST 2006


wapur.com wrote:

> Hello,
> I am tryig to assign a callback to a slider. It works as below if I 
> write direcly to the main function without any class declaration.
>  
> Fl_Value_Slider* slider11;
> slider11 = new Fl_Value_Slider(10,10, 10, 10, "slider11:");
>  
> void slider11_cb(Fl_Widget* in, void*){...;}
> slider11->callback(slider21_cb,NULL);
>  
> But then i start to write a class named eubStudio.
>  
> void eubStudio::slider11_cb(Fl_Widget* in, void*){}
> and I when I try to assign this function to the slider in a function 
> of this class I got the following error
> slider11->callback(slider11_cb,NULL);
>  
> error C2664: 'void Fl_Widget::callback(Fl_Callback (__cdecl *),void 
> *)' : cannot convert parameter 1 from 'void (Fl_Widget *,void *)' to 
> 'Fl_Callback (__cdecl *)'
>         None of the functions with this name in scope match the target 
> type

FLTK callbacks must be static void methods. You cannot make them 
non-static member functions of a class. If your intention is to use the 
class's methods, you would pass the class to the callback as calldata....

static void Callback( Fl_widget *w, void *data)
{
  MyClass *myClass = (MyClass *) (data )
.....
}

myClass::SomeMethod()
{
    slider11->callback(Callback, this);
}


-karthik

>  
>  
> Any ideas?
> Thanx
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>  
>


More information about the Insight-users mailing list