Re: [gtk-list] Passing a struct through a gtk_connect_signal



Rafael Peregrino da Silva wrote:
> Hi ALL :-)

 Oi, tudo bem? :)

> I'm trying the all day to pass a struct as last argument through a
> gtk_connect_signal, but I must be overlooking something, so that this is
> not working at all :(
> 
> I have the following piece of code:
> 
> static void
> press_3rd_button_event (GtkWidget *widget,
>                         GdkEventButton *event,
>                         gpointer user_data)
> {
>   /* We only do something if the third (rightmost mouse button
>    * was released
>    */
>   if (event->type==GDK_BUTTON_PRESS && event->button==3)
>     {
>       printf("Original ymax = %g\n",user_data.orig_ymax);
>     }
> }

 user_data is a pointer to the structure. So its members should
be read this way:

 user_data->orig_xmin;
 user_data->orig_xmax;
 user_data->orig_ymin;
 user_data->orig_ymax;

 Also make sure the user_data is of the type "pointer-
to-that-structure" you have created. If you pass it to
press_3rd_button_event as a gpointer, the function will
not know what members it has.

> P.S. (Of course I could pass the struct as global variable to the function,
> but I have learned in this list that this is no good GTK programming :-)

 If you can avoid it, your code will look much better.

--
Pedro Medeiros
Brasila - DF, Brazil



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