problem with combos



hi guys,

i have the following problem:
i use a combo box with some strings in its list and
every time the user selects a string, i want all the
previous strings to be removed from the list.
for example if the user selects item 3, i want items
0, 1 and 2 to be removed.
(the code is at the end of the mail)
when i select string 1, string 0 is deleted normally,
but if i select after this string 3(or anything else), 
strings 1&2 are deleted and i get this:

Gtk-CRITICAL **: file gtkobject.c: line 1163 (gtk_object_ref): assertion `object->ref_count > 0' failed.

Gtk-CRITICAL **: file gtkobject.c: line 1163 (gtk_object_ref): assertion `object->ref_count > 0' failed.

Gtk-CRITICAL **: file gtkobject.c: line 1173 (gtk_object_unref): assertion `object->ref_count > 0' failed.

Gtk-CRITICAL **: file gtkobject.c: line 1173 (gtk_object_unref): assertion `object->ref_count > 0' failed.

or sometimes (in my real program, not the following) it receives signal SIGSEGV
the debugger shows this:
Program received signal SIGSEGV, Segmentation fault.
0x40108965 in gtk_window_real_set_focus (window=0x8069710, focus=0x8083520) at gtkwindow.c:1602
can anybody help me to find out where's the fault?
(i use gtk+ version 1.2.4)

thanx in advance

here is the sample code:
#include <gtk/gtk.h>

GList *glist=NULL;
gint active=0;
GtkWidget *combo;

static gint delete_callback(GtkWidget *widget, gpointer data)
{
    gtk_main_quit();
    return(FALSE);
}

void callback(GtkEntry *comboentry, gpointer data)
{
    GList *l;
    gint cnt=0;
    if (active)
    {
        l=g_list_first(glist);
        while (g_strcasecmp(l->data, gtk_entry_get_text(comboentry)))
        {
            g_print("data %s deleted\n", (gchar *) l->data);
            glist=g_list_remove(glist, l->data);
            g_free(l->data);
            cnt++;
            l=g_list_first(glist);
        }
        gtk_list_clear_items(GTK_LIST(GTK_COMBO(combo)->list), 0, cnt);
    }
}

int main (int argc, char *argv[])
{
    GtkWidget *window;

    gtk_init(&argc, &argv);
    window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT(window), "delete_event",
                        GTK_SIGNAL_FUNC(delete_callback), NULL);
    combo=gtk_combo_new();

    glist = g_list_append(glist, "String 1");
    glist = g_list_append(glist, "String 2");
    glist = g_list_append(glist, "String 3");
    glist = g_list_append(glist, "String 4");
    gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed", GTK_SIGNAL_FUNC(callback), NULL);
    
    gtk_combo_set_popdown_strings( GTK_COMBO(combo), glist);
    gtk_container_add(GTK_CONTAINER(window), combo);
    gtk_widget_show_all(window);
    active=1;
    gtk_main();
    return 0;
}




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