Re: GList empty after iteration?
- From: Bernhard Schuster <schuster bernhard googlemail com>
- To: Craig <craigbakalian verizon net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: GList empty after iteration?
- Date: Mon, 12 Sep 2011 22:21:34 +0200
2011/9/12 Craig <craigbakalian verizon net>:
Hi All,
I am confused about GList. My application is parsing a file and creating
midi data with it. I am using GList to store the midi data. ÂI have
created a GtkListStore to view the parsed data (to insure I am parsing
the data properly). ÂSo, below I iterate through the GList and "copy"
the data into a tree view. ÂBut, I am shocked to see that after I
iterate through the GList, I cannot iterate through the list again. ÂI
have debugged the list after the iteration with g_list_length(events)
which shows the list length at 0. ÂWhat is up with this? ÂThe first
while loop has data, the second while loop has not data. The code is
below-->
   ÂGtkTreeIter tree_iter;
   Âevents = g_list_reverse(events);
shallowcopy = events;
   Âevents = g_list_first(events);
   Âwhile(events)
   Â{
       Âgtk_list_store_append (list_store, &tree_iter);
       Âstruct midi_event *me = events->data;
       Âgtk_list_store_set(list_store, &tree_iter,
                 0, me->time_stamp,
                 1, me->event_type,
                 2, me->message1,
                 3, me->message2,
                Â-1);
       Âevents = g_list_next(events);
   Â}
   Â/// this is where the list appears to be empty!!!!
events = shallowcopy;
   Âwhile(events)
   Â{
       Âg_print("midi event \n");
       Âevents = g_list_next(events);
   Â}
Thanks for any help!
Your first loop ands when your event is zer0. Youn need to use a
second pointer for your second iteration which still points to the
first item in the actual list.
Hope that helps.
Regards
Bernhard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]