add list to gtk_tree_view in C

1.2k views Asked by At

folks,

im gonna tryin to make a little function which has something todo with the Gtk_tree_view that i've made, the error response such as like this :

(main:8026): Gtk-CRITICAL **: IA__gtk_tree_view_get_model: assertion `GTK_IS_TREE_VIEW (tree_view)' failed

(main:8026): Gtk-CRITICAL **: IA__gtk_list_store_append: assertion `GTK_IS_LIST_STORE (list_store)' failed

(main:8026): Gtk-CRITICAL **: IA__gtk_list_store_set_valist: assertion `GTK_IS_LIST_STORE (list_store)' failed
^C

and the source, here you go :

 void addlist(bahan *unit, const gchar *str)
    {
        GtkListStore *store;
        GtkTreeIter iter; // penyambung store_append and store_set

        store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(unit->treeview_aktifitas)));

        gtk_list_store_append(store, &iter); // need unary &, coz iter aint define like a pointer
        gtk_list_store_set(store, &iter, 1, str, -1);
    }

as you've figured , the structure of 'unit' was supposed like this :

  typedef struct
    {
        GtkWidget *window;
        GtkWidget *notebook;
        GtkWidget *start;
        GtkWidget *verbose;
        GtkWidget *settings;
        GtkWidget *about;
        GtkWidget *statusbar;
        GtkWidget *treeview_aktifitas;
        guint statusbar_id;
    } bahan;

and connected by this :

  unit->treeview_aktifitas = GTK_WIDGET(gtk_builder_get_object(main,"treeview1"));

in the real case, im using 'glade 3', and have two columns on glade file, how to set on gtk_list_store_set ?

very appreciate any further help :)

1

There are 1 answers

0
capede On

well, i've found the fault now

    gtk_list_store_set(store, &iter, 1, str, -1);

just because my columns are two ,thus i need to

    gtk_list_store_set(store, &iter, 0,"aku", 1, "tes", -1);

which 0 represent first column and 1 represent next column, and so on -_-'