nomadicME
nomadicME

Reputation: 1409

64-bit system, GINT_TO_POINTER(i) / GPOINTER_TO_INT(p)

I'm having the hardest time getting an integer passed to a callback function, since the last argument of g_signal_connect is required to be a pointer. Here is where I connect the signal to the callback:

for (i=0;i<10;i++)
{

    ...
    gtk_widget_set_events(tab_ebs[i],GDK_BUTTON_PRESS_MASK);
    g_signal_connect (G_OBJECT (tab_ebs[i]), "button_press_event", G_CALLBACK (tab_clicked_cb), GINT_TO_POINTER(i));

}

and here is the callback:

void tab_clicked_cb (gpointer p)
{
    printf("tab #%d clicked\n", GPOINTER_TO_INT(p));
}

What I get in stdout, are statements such as:

tab #6578976 clicked
tab #6579264 clicked
tab #6579552 clicked
tab #6579840 clicked

When I only have ten tabs. How can I pass an integer to a callback fcn on a 64 bit system? Thanks.

Upvotes: 0

Views: 1073

Answers (2)

nomadicME
nomadicME

Reputation: 1409

nos got me half way there. Turns out I was also missing an argument for the event in my callback function. Here is the form that worked:

void tab_clicked (GtkWidget *widget, GdkEventButton *ev, gpointer p)
{
    printf("tab #%d clicked\n", GPOINTER_TO_INT(p));
}

Upvotes: 2

nos
nos

Reputation: 229108

Your callback function is likely wrong, most Gtk callback handlers passes the widget that originated the event as the first parameter to the callback function. So it should be e.g.

void tab_clicked_cb (GtkWidget *widget, gpointer p)
{
    printf("tab #%d clicked\n", GPOINTER_TO_INT(p));
}

Edit, The Gtk docs are not at all clear on what it's callback handler is for the button_press_event, the docs read as the callback handler for button_press_event doesn't receive any arguments.

Upvotes: 0

Related Questions