Question

I tried passing a two-dimensional array as argument to a function in GTK, without success. How can I edit the order of the buttons in the array?

GtkWidget *botones[4][4];

...

g_signal_connect(G_OBJECT(botones[0][0]), "clicked", G_CALLBACK(borra), botones);

...

void borra(GtkWidget *widget, gpointer info)
 {
    GtkWidget **elementos= (GtkWidget*) info;

     ...

 }
Was it helpful?

Solution

botones is a 4*4 array of GtkWidget *, when you call g_signal_connect, you cast it to a gpointer which is typedef for void *, then in the callback function, you should cast the gpointer back to a pointer to an array of 4 GtkWidget * like this:

GtkWidget * (*elementos)[4] = (GtkWidget *(*)[4])info;

Then you can use elementos[0][0] to access the 2-D array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top