GtkTreeStore/GtkTreeModel problem in C
- From: Tvrtko MajstoroviÄ <t m nixstuff gmail com>
- To: gtk-app-devel-list gnome org
- Subject: GtkTreeStore/GtkTreeModel problem in C
- Date: Wed, 09 Jul 2008 23:17:44 +0200
I'm having a problem with my application that uses GtkTreeView which is
connected to one GtkTreeStore. I created GtkTreeStore as a global
variable so I can access to it from all parts of my project. Is that
right? or wrong? I'm new to GTK+. Basically I understand most of the
widgets I encountered but this one (tree views and tree models) are
giving me a headache.
I'm using Anjuta with libglade. I created gladefile with treeview in it,
and created "init_tree" function that initializes "treeview1" and as
said before one global "GtkTreeStore * media_catalog":
GtkTreeStore * media_catalog;
void
init_tree ( GtkWidget * view)
{
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Stored Media");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer,
"text", 0);
media_catalog = gtk_tree_store_new ( 1, G_TYPE_STRING);
gtk_tree_view_set_model( GTK_TREE_VIEW ( view),
GTK_TREE_MODEL ( media_catalog));
g_object_unref ( media_catalog);
}
now... I have this:
GtkWidget*
create_window (void)
{
GtkWidget * window;
GtkWidget * view;
GladeXML * gxml;
gxml = glade_xml_new ( GLADE_FILE, NULL, NULL);
/* This is important */
window = glade_xml_get_widget ( gxml, "mc-window");
view = glade_xml_get_widget ( gxml, "treeview1");
init_tree ( view);
glade_xml_signal_autoconnect ( gxml);
return window;
}
so when I call:
GtkWidget *window = create_window();
// ... connect delete and destroy events ...
gtk_widget_show (window);
... the tree view "treeview1" is displayed as predicted.
Next, the app uses one more dialog window that needs to add more info to
the "media-catalog" store. In that dialog I have a button, with signal
handler like this:
void
on_add_button_clicked (GtkWidget * widget,
gpointer data)
{
GtkTreeIter iter;
gtk_tree_store_append ( media_catalog, &iter, NULL);
gtk_tree_store_set ( media_catalog, &iter, 0, "hahaha", -1);
}
but, when clicked nothing shows up in the "treeview1". Can anyone help
me, direct me in right direction? please!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]