Re: [gtk-list] Member functions as callbacks?



Jonathan Belson wrote:

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

Maybe you forgot, that C++ pushes the "this" operator on the
stack as the first parameter when calling class member
functions, so your code probably cannot work. Try something
like this

void my_button_callback( GtkWidget *button, preview* win )
{
  win->button_pressed( button, "pressed" );
};

preview::open_window(void)
{
  // snip

  gtk_signal_connect(GTK_OBJECT(button), "clicked",
    GTK_SIGNAL_FUNC(my_button_callback),  (gpointer) this );

  gtk_widget_show(button);
}

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



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