Re: question about resizing & combos
- From: Giaslas Georgios <giaslas ceid upatras gr>
- To: gtk-list redhat com
- Subject: Re: question about resizing & combos
- Date: Wed, 27 Oct 1999 00:05:40 +0300 (EET DST)
Thank you Gustavo for replying so quick
i tried to put g_free(l->data) before g_list_remove
but i get a segmentation fault when the program tries to execute g_free
i also checked with gdb that 'while' doesn't ever result
in an endless loop.
So, there must be another problem
Thanx anyway
-----------------------------------------
> 2) i have a combo box and when the user selects
> a string i want all the strings before this to be removed.
> i've done it and when i change the comboentry using
> arrow keys it's ok. but when it's changed using the
> mouse i get a segmentation fault.
> Is it a bug or it's my fault?
> please try the following little program to see what
> i mean exactly.
>
> (I use gtk+ version 1.2.6)
>
> Please reply this time...
>
> Thank you all
>
> -----------------------------
> #include <gtk/gtk.h>
>
> GList *glist=NULL;
> gint active=0;
> GtkWidget *combo;
> GtkWidget *window;
>
> 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);
> g_free(l->data) should come before g_list_remove because it is
>not guaranteed that the location pointed by 'l' is valid after you remove
>it from the list.
> cnt++;
> l=g_list_first(glist);
> }
> Also, you should take care that this previous 'while' doesn't
ever
>result in an endless loop.
> gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
> }
> }
>
> int main (int argc, char *argv[])
> {
> 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]