Re: GList and combobox problem



Here's my piece of code I create a selection list in a container box.
Hope this helps.
  cp = LaffCellNameIterator(db,1);
  while (cp)
  {
    gchar         *string ;
    GtkWidget     *label,*list_item ;
    if (! strcmp("BARINFO",cp)) goto NEXT;
    label     = gtk_label_new(cp);
    list_item = gtk_list_item_new();
    gtk_container_add(GTK_CONTAINER(list_item), label);
    gtk_widget_show(label);
    gtk_container_add(GTK_CONTAINER(list), list_item);
    gtk_widget_show(list_item);
    gtk_label_get(GTK_LABEL(label), &string);
    gtk_object_set_data(GTK_OBJECT(list_item),
                        list_item_data_key,
                        string);
    NEXT: cp = LaffCellNameIterator(db,0);
  }

Marco Cova wrote:

> Hi all.
> I have the following problem.
> I want to fill a GList *list with the names of files stored in a
> directory and then use this list together with a combobox. So, I expect
> to see the files' names as popdown strings, but all I get is some
> garbage. A part of the code follows:
>
> /* function I use to initialize the list with files' names */
> GList *init_list(GList **list, char *directory)
> {
>  DIR *dp;
>  struct dirent *de;
>
>  dp = opendir(directory);
>   while((de = readdir(dp)) != NULL)
>   {
>    *list = g_list_append(*list, de->d_name);
>   }
>
>   closedir(dp);
>   return(*list);
> }
>
> /* this is in main() */
>  GList *list;
>  GtkWidget *combo;
>  int i;
>
>  list = NULL;
>  list = init_list(&list, "/home/user/dir");
>  /* this correctly outputs files' names */
>  for(i = 0; i < g_list_length(list); i++)
>   printf("DEBUG: list's element number %d is %s\n", i, g_list_nth(list,
> i)->data);
>
>  gtk_combo_set_popdown_strings(GTK_COMBO(combo), list);
>  gtk_widget_show(combo);
>
> I searched more info in the tutorial and the reference, but I couldn't
> find a solution. Any help is much appreciated,
> thanks,
> Marco.
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list





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