Re: C++-classes.
- From: Jeff Franks <jcf tpg com au>
- To: David Larsson <dls home se>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: C++-classes.
- Date: Wed, 23 Oct 2002 08:45:58 +1000
David Larsson wrote:
GtkClass::GtkClass()
{
button = gtk_button_new();
gtk_signal_connect(GTK_OBJECT(button),
"clicked", GTK_SIGNAL_FUNC(&GtkClass::Test), 0); // C++ doesn't use NULL. It's a C macro.
}
Ah, then I came up to another problem. If you then want to modify the "calling" class variable, for example
the GtkWidget *button.
If you do a:
void GtkClass::Test()
{
gtk_widget_hide(button);
// or a GtkClass::button?
// or even call another method in GtkClass?
}
it doesn't seem to work. How can i fix this?
Pass the pointer you want passed to the callback as the user data:
Solution one:
GtkClass::GtkClass()
{
button = gtk_button_new();
gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(&GtkClass::Test), button);
}
void GtkClass::Test(GtkWidget* widget, GtkWidget *button)
{
gtk_widget_hide(button);
}
Solution two: looks cleaner as it swaps the widget and user_data arguments.
GtkClass::GtkClass()
{
button = gtk_button_new();
gtk_signal_connect_swapped(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(&GtkClass::Test), button);
}
void GtkClass::Test(GtkWidget *button)
{
gtk_widget_hide(button);
}
Jeff Franks
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]