Member functions as callbacks?




Hiya

Hope I'm not overlooking anything obvious here, but I`m having problems
when I try and use member functions as callback functions, eg.


preview::open_window(void)
{
        preview_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(preview_window), "Preview");

        button = gtk_button_new_with_label("Hello");
        gtk_container_add(GTK_CONTAINER(preview_window), button);

        gtk_signal_connect(GTK_OBJECT(button), "clicked",
                GTK_SIGNAL_FUNC(button_pressed),  (gpointer) "pressed");

        gtk_widget_show(button);
        gtk_widget_show(preview_window);

}

void preview::button_pressed(GtkWidget *widget, gpointer p)
{
        g_print("Button pressed\n");
}


The problem is that the pointer 'widget' is completely different from what it
should be, ie. not equal to 'button' as you'd expect.  I can access it by
passing 'this' as an argument to the callback function, but I don't see
why I should need to do this.  If I make button_pressed() a non-member
function, widget == button as you'd expect.

Do I need to do anything special to use gtk with C++?

Thanks for any help

C-YA
Jon



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