You are not logged in.
Hi,
This is getting as frustrating as it is embarrasing - I want to use the "gpointer user_data" argument of a GTK+ callback function to set the value of two variables in another part of the program. In this simplified example I want to use user_data to set the value of two int's in a structure:
typedef struct { int x, y; } xy_t;
void some_callback( GtkWidget *widget, gpointer user_data )
{
(xy_t *) user_data->x = some_value;
(xy_t *) user_data->y = other_value;
............
}
However I get the following error message: ...dereferencing 'void *' pointer
Not withstanding <my stupid mistakes>, what is the way to pass on more than one user variable to a GTK+ callback function?
My thanks in advance.
Regards
Neoklis ... Ham Radio Call: 5B4AZ
Offline
Have you tried the following:
typedef struct { int x, y; } xy_t;
void some_callback( GtkWidget *widget, gpointer user_data )
{
((xy_t *) user_data)->x = some_value;
((xy_t *) user_data)->y = other_value;
............
}
It may be that you cast the member (x / y) of user_data instead of user_data itself.
Offline
Or to avoid that ugly cast every time:
typedef struct { int x, y; } xy_t;
void some_callback( GtkWidget *widget, gpointer user_data )
{
xy_t *point = user_data;
point->x = some_value;
point->y = other_value;
............
}
Offline
Have you tried the following:
typedef struct { int x, y; } xy_t; void some_callback( GtkWidget *widget, gpointer user_data ) { ((xy_t *) user_data)->x = some_value; ((xy_t *) user_data)->y = other_value; ............ }
It may be that you cast the member (x / y) of user_data instead of user_data itself.
Ahh, thanks! It worked - well, except that I now got "error: 'some_value' undeclared" ;-)
Now I can go to bed less embarrassed - I would never have thought of that!
Regards
Neoklis ... Ham Radio Call: 5B4AZ
Offline
Or to avoid that ugly cast every time:
typedef struct { int x, y; } xy_t; void some_callback( GtkWidget *widget, gpointer user_data ) { xy_t *point = user_data; point->x = some_value; point->y = other_value; ............ }
Exactly this is what was driving up the wall - I tried this and it was accepted, so I just couldn't understand why the ugly casting form wasn't. But I also assumed that this form would not give me the right results, so I didn't even try it in practice. And all this after writing a fair number of apps for Linux... ;-)
Regards
Neoklis ... Ham Radio Call: 5B4AZ
Offline