Hi,
Im new to this forum and I like what i seen so far. Could anyone tell me whats wrong with this program below. I get a segmentation fault when pressing the button.
Code:
#include <gtk/gtk.h>
typedef enum { APPLE, BANANA } Fruit_Type;
typedef struct Fruit {Fruit_Type ft;} Fruit;
void PealAFruit(Fruit_Type fruit)
{
g_message ("PealAFruit called");
}
static gboolean button_clicked( GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
Fruit *afruit = (Fruit*)data;
PealAFruit(afruit->ft); /*here a segmentation fault */
return TRUE;
}
int main( int argc, char *argv[] )
{
g_message ("start");
GtkWidget *window;
GtkWidget *button;
Fruit *afruit;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label ("Hello World");
if ( (afruit = (Fruit*)g_malloc(sizeof(Fruit))) != NULL)
{
afruit->ft = APPLE;
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (button_clicked), afruit);
}
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}