[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Still problems with gtk_list_store_append
- From: Michael Unterkalmsteiner <miciu gmx de>
- To: gtk-app-devel-list gnome org
- Subject: Re: Still problems with gtk_list_store_append
- Date: Tue, 2 Mar 2004 21:36:23 +0100
On Mon, Mar 01, 2004 at 02:28:24PM +0100, Jesper Mørk wrote:
> Hi List
>
> I didn't really resolve the problem the last time so i'm trying again in
> hope that someone can help me. Its damn frustrating that it wont work.
>
> To summarize the problem. I'm trying to add som data to a list store. It
> works fine for the first rows but then suddenly it crashes with a
> segfault. As far as I can tell it crashes when calling
> gtk_list_store_append(). The data I'm trying to populate the list store
> with comes from a GList of a struct that looks like this:
>
> typedef struct {
> char * mid;
> char * title;
> char * director;
> char * year;
> char * genre;
> char * language;
> char * runtime;
> char * imdb;
> char * media;
> char * mediasource;
> char * mediaformat;
> char * discnumber;
> char * seen;
> char * borrowed;
> } Movie;
>
> My code for populating the list store is:
>
> int repopulate_list(GtkWidget * widget, GtkListStore * model){
> GtkTreeIter iter;
> GList * movies = NULL;
> GList * movie_element;
> Movie * movie = NULL;
> FILE * fptr;
> int i = 0;
>
> printf("Clearing...\n");
> /* Clear list for repopulation */
> gtk_list_store_clear(model);
>
> printf("Open file for reading...\n");
> /* Populate list store */
> if(fopen(selected_filename, "r") != NULL){
> movies = listMovies(selected_filename);
> } else {
> fptr = fopen(selected_filename, "w");
> fprintf(fptr, "<?xml version=\"1.0\"?>\n");
> fprintf(fptr, "<movies></movies>\n");
> }
>
> printf("Get first...\n");
> movie_element = g_list_first(movies);
> while(movie_element != NULL){
>
> /* De reference list data */
> movie = (Movie*)movie_element->data;
>
> /* Set values on list... */
> printf("Appending...\n");
> gtk_list_store_append(model, &iter);
> printf("Set...\n");
> gtk_list_store_set(model, &iter, 0, movie->mid, 1, movie->title, 2,
> movie->imdb, 3, movie->mediasource, 4, movie->mediaformat, 5,
> movie->borrowed, -1);
>
> /* Go to next element in list */
> movie_element = g_list_next(movie_element);
> }
>
> return 1;
> }
You must allocate memory for your struct. Look in your glib-doc for
g_new(), g_new0().
>
> What is really strange is that when i start the program with an empty
> list everything is fine, and I can even add lines for a while without
> any troubles. But after it crashes with the segfault it wont event do
> the first few lines. Output from the program after the first initial
> segfault:
Typical symptoms of "wild pointers" are undefinable segfaults,
because they point *somewhere* in your memory.
hth,
Michael
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]