Re: Passing a struct through a gtk_connect_signal



On Mon, Mar 13 (2000), Rafael Peregrino da Silva wrote:

First of all I've never committed any program in GTK -- I'm starting to
learn:)), but

[...]
> static void 
> press_3rd_button_event (GtkWidget *widget,
> 			GdkEventButton *event,
> 			gpointer user_data)
[...]
>       printf("Original ymax = %g\n",user_data.orig_ymax);

Here user_data is a pointer not a structure! It does not have any
members and that's what compiler says:
> test.c: In function `press_3rd_button_event':
> test.c:39: request for member `orig_ymax' in something not a 
> structure or union
> make: *** [testgtkplot2.o] Error 1 
[...]

But you can cast user_data to be pointer to your struct. E.g if you do:

typedef struct {
    gdouble orig_xmin;
    gdouble orig_xmax;
    gdouble orig_ymin;
    gdouble orig_ymax;
} axis_lim_t;

then you can in your main function do:

static axis_lim_t axis_lim = {-1,1,-1,1.4};
and in your callback:

printf("Original ymax = %g\n", ((axis_lim_t*)user_data)->orig_ymax);

					Best regards
PS. I'm not sure whether those parentheses are needed (I can never
remember the operator priorities :-)))
-- 
    ____   _  ___
   /  | \_/ |/ _ \		Andrzej Marek Ostruszka
  / _ |     | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow)
 /_/ L|_|V|_|\___/	(PGP <-- finger ostruszk@order.if.uj.edu.pl)



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