Problems with GtkTreeStore

Hi guys!

    I need your valuable help with I subject that is driving me crazy!!!  I am trying to create a TreeStore 
from a file, and to fill from another source file. After getting many segmetation faults and assertion 
failures, I've realized that I am not doing it in the right way. This is what I want:

(+) ==> Device 1
  |               |          
  |            (+) ===> Attribute 1
  |              |
  |            (+) ===> Attribute 2
(+)==> Device 2 
  |              |
  |            (+) ===> Attribute 1
  |              |
  |            [...]
  |              |
  |            (+) ===> Attribute n
(+) ==> Device n

In my application's main window it should be displayed some kind of devices monitored from my pc, plus their 
correspondent internal attributes that will be fetched from the functions within a different source file, as 
I stated before:

This is an overall of what i have:


GtkTreeStore *store;

GtkTreeIter *parent;
GtkTreeIter *child;

GtkWidget *view;

GList devList; //Here the present devices are stored

void deviceList(){

//This function populates the tree with the present devices but is not able to 
//access their individual attributes.

//We will be monitoring four parameters

view =  gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
renderer = gtk_cell_renderer_text_new();

gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), 0, "name", renderer, "text", 0, NULL);
[...]    //here come the other three gtk_tree_view_intsert_column_with_attributes() func...

gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store));

//Now I will start to populate the tree:

for(i = 0 ; i < g_slist_length(deviceList); i++){

    //In this omitted part we retrieve the first device from the list, and store in a type called "device"

    gtk_store_append(store, &parent, NULL);

    gtk_tree_store_set(store, &parent, 
                                                     0, (char *) device->name, -1);

    device_attributes(device->id);    //Here is where my nightmares start! :-)
                                                  //This function should access each device and add their 
attributes to the tree

int main(int argc, char **argv){

    gtk_init(&argc, &argv);

    [...]    //We fill GList with present devices

    deviceList();    //The above mentioned funcion

    main_window();    //GUI function accessed through a given interface (interface.h)





extern GtkWidget *view;

//The only relevant part in this file is in main_window()



frame = gtk_frame_new("Configuration");

gtk_container_add(GTK_CONTAINER(frame), view);


//Here the rest of the windows which are part of my application



extern GtkTreeIter parent;
extern GtkTreeIter child;
extern GtkTreeStore *store;

device_attributes(int id){    //id will identify the device to be accessed


//We access the device internally and get the appropiate data that will be converted into
//string before is showed onscreen.

gtk_tree_store_append( store, &child, &parent);    //I try to add a new line corresponding to the processed 

gtk_tree_store_append(store, &child,                             //Here is where my app crashes
                                                        0, (char *) attr1,
                                                        1, (char *) attr2,
                                                        2, (char *) attr3,
                                                        3, (char *) attr4,


There's no problem at compiling time, but as I start the application a segmentation fault says "hello" from 
my monitor :-( 

I hope that you can understand more or less what I am trying to implement. I suppose that what I want is 
achieved in a very different way from what I'm trying, so I would really be very thankful if you can give 
some hints about the correct way to do this or any url to a good tutorial that explains this situation.

Thank you very much for your attention!!!


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