Segmentation fault in code - possible bug?



Hello,
In my quest to figure out why this gtksheet stuff isn't working,
I've been looking at the gtkitementry stuff, which has eventually led
me to the gtkentry widget.

I've created a bit of code below...

#include <gtk/gtk.h>

static GtkContainerClass *parent_class = NULL;

void
quit ()
{
g_print("quiting\n");
  gtk_main_quit();
}


void my_destroy( GtkWidget *child )
{
  g_print("my_destroy: destroying a %s\n", G_OBJECT_TYPE_NAME (child));
  gtk_widget_destroy (child);
}

int close_it(GtkWidget *but, GtkWidget *shet)             
{
 if (GTK_IS_ENTRY(shet) && GTK_IS_WIDGET(shet))
   {
    g_print("destroying entry\n");
    gtk_widget_destroy(shet);
    //gtk_widget_ref(shet);
    //shet = NULL;
    //gtk_entry_finalise(shet);
   }
}


int main ( int argc, char *argv[])
{    
GtkWidget *window;
GtkWidget *sheet;
GtkWidget *vbox;
GtkWidget *entry;
GtkWidget *button;

gtk_init (&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

entry = gtk_entry_new();

button = gtk_button_new();

vbox = gtk_vbox_new(TRUE, 1);
gtk_container_add(GTK_CONTAINER(window), vbox);



gtk_widget_set_usize(GTK_WIDGET(window), 900, 600);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
                      GTK_SIGNAL_FUNC (quit), NULL);

g_signal_connect_after (G_OBJECT (button), "clicked", G_CALLBACK (close_it), ent
ry);

gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, TRUE, 0);
gtk_box_pack_end(GTK_BOX(vbox), entry, FALSE, TRUE, 0);

gtk_widget_show_all(window);


gtk_main();
return(0);
}


When I run the resulting program and press the button at the top of the window
it gets rid of the gtk_entry. If I keep pressing this button, I get a
segmentation fault.

If I replace the entry widget with a button say, (and other code as well)
I can keep pressing the top button without any segmentation fault.

Something buggy with gtk entry? Or am I just doing something really stupid?

Tried this with versions 2.2.1 and 2.2.4 and also tried on another machine.

Cheers

Joe
-- 



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