Alin Enachescu
Alin Enachescu

Reputation: 81

GTK: g_signal_connect() send wrong address

I have this piece of code:

int gui_showScore(struct Game *game)
{
    printf("%p\n", game);
    return NO_ERROR;
}

int gui_createButtonShowScore(GtkWidget *fixed, GtkWidget **showScore,
                          struct Game *game)
{
    if (fixed == NULL)
        return POINTER_NULL;

    printf("%p\n", game);
    *showScore = gtk_button_new_with_label("Show score");
    gtk_fixed_put(GTK_FIXED(fixed), *showScore, 620, 50);
    gtk_widget_show(*showScore);
    g_signal_connect(G_OBJECT(*showScore), "clicked",
                     G_CALLBACK(gui_showScore), game);

    return NO_ERROR;
}

Why when is pressed the button, is called gui_showScore() with other pointer?

e.g: In gui_createButtonShowScore() the pointer value game is 0x1249590 and when is pressed the button is called gui_showScore() and the pointer value game is 0x12202b0. Why?

How can resolve this problem?

Upvotes: 1

Views: 96

Answers (1)

unwind
unwind

Reputation: 400049

Read the documentation for the "clicked" signal:

void user_function(GtkButton *button, gpointer   user_data)

The first argument is always always the object that received the signal, the last argument is the user pointer where the data supplied when you connected the handler is passed.

Upvotes: 3

Related Questions