Re: [gtk-list] Callback function troubles



Brent Briggs wrote:
> 
> I have been working on a robotics program and have never been able to
> get my widgets to call my functions the way that I want them to.
> I have a callback function that looks like this:
> 
> void init_arm_callback(GtkWidget *widget, GdkEvent *event,
> command_struct *data)
> {
>   cout << "data in init_arm_callback :\n";
>   cout << "data->fdesrcipter " << data->fdescripter << "\n";
>   arm_initialize(data);
> }
> 
...
> I am calling this callback with a button like so:
> 
>   /*setup the initialize button */
>   button = gtk_button_new_with_label ("Re-Initialize");
>   gtk_container_add (GTK_CONTAINER (control_vbox), button);
>   gtk_widget_show (button);
>   gtk_signal_connect (GTK_OBJECT (button), "clicked",
>         GTK_SIGNAL_FUNC (init_arm_callback),
>         &command_data);
> 
> The values in the structure seem to get changed when the data is passed
> fron gtk_signal_connect (......) to init_arm_callback(........). For
> instance, command_data.fdescripter has a value of 3 when checked from
> main  but when the same value is checked from
> init_arm_callback(........) I get a value of something like 607312 . Why
> is this happening? This doesn't make sense to me but then again I am a
> newbie to GTK developement. Can someone Please help me out?
> 

I've been having the same type of problems...  PLEASE try your callback
WITHOUT the GdkEvent *event arg... i.e.
  void init_arm_callback(GtkWidget *widget, (gpointer)data)
  {
   command_struct *ptr = (command_struct*)data;
   then... use the ptr! 
  }

I've been getting the "data" in the second arg...  I'm still trying to
figure out if it is g++ 2.7.2.3, the cvs version of gtk+ or some silly
thing I'm doing wrong!  If you are having the same problem, maybe we
can narrow it down.

Greg Kaup



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]