Re: problem with gtk filetree



On Thu, Apr 26, 2001 at 04:22:57AM -0400, Glitch wrote:
> Helmethead wrote:
> 
> > On Wed, Apr 25, 2001 at 11:58:36PM -0400, Glitch wrote:
> > 
> >> hello,
> >> 
> >> I got Developing Linux Applications Using GTK+ (written by Eric Harlow).
> >> 
> >> In it there is an example of a Gtk Tree and Gtk List.  It basically uses 
> >> the directories and files in the CWD and displays the contents in a tree 
> >> with leafs.
> >> 
> >> I can get the application to compile just fine however when I try 
> >> selecting a directory or file I get a seg fault. I can hit the + or - 
> >> sign to expand or collapse a branch but selecting anything but the top 
> >> node causes a seg fault. Here is the actual message:
> >> 
> >> Gtk-WARNING **: invalid cast from `(unknown)' to `GtkList'
> >> Segmentation fault
> >> 
> > 
> > 
> > Such errors usually happen when u pass a NULL to a gtk_list_* function that doesn't want a NULL
> > Do you know that (as of gtk2.0) GtkList is by twice obselete? use GtkCList ferchrissakes, or if you are writing for 2.0, GtkTreeView/GtkListStore :)
> > 
> > Course I don't know how to write for any of the above. Maybe GtkList is easier or something. And you do have a book on it. But it's gone way out of favor..
> 
> well, i haven't installed 2.0 and so i'm working with old code, and 
> since im learning *and* learning from a now old book, i feel in some 
> ways i should stick to the old code then since the book uses that.
> 
> anyway, I looked thru my code and didn't seee any explicit use of NULL 
> but I know that it isn't necessarily that easy of a fix.  After looking 
> at my code and what is printed to the xterm i noticed that a sprintf 
> statement i have isnt being reached so the program must stop somewhere 
> before that.  The sprintf statement is on line 59. I think my cast of 
> GTK_LIST(listbox) in the PopulateListbox function isn't working right 
> for some reason, but I could be wrong.

Sounds right, listbox is completely uninitialized..
Maybe you're not clear on what GTK_LIST (and similar) macros are supposed to do? At any rate they don't pull a listbox from thin air :)
You'll want to somehow get the listbox from the CreateTree function to PopulateListbox. Save it in a global variable or something.

> static void PopulateListbox(char *szPath)
> {
>   GtkWidget *listbox;
>   GtkWidget *item;
>   DIR *directory;
>   struct dirent *dirEntry;
>   struct stat fileStatus;
>   char buffer[MAX_PATH];
>   gtk_list_clear_items(GTK_LIST(listbox),
>                        0,
>                       g_list_length(GTK_LIST(listbox)->children));
>   directory = opendir(szPath);
>   while (dirEntry == readdir(directory))
>    {
>      if (!strcmp(dirEntry->d_name, "..") ||
>          !strcmp(dirEntry->d_name, ".")) {
>      }
>       else {
>            sprintf(buffer, "%s/%s", szPath, dirEntry->d_name);
>            if (!IsDirectory(buffer)) {
>             item = gtk_list_item_new_with_label(dirEntry->d_name);
>             gtk_container_add(GTK_CONTAINER(listbox), item);
>             gtk_widget_show(item);
>             AddListItem(listbox, dirEntry->d_name);
>       }
>     }
>   }
> closedir(directory);
> }




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