GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Oct 26, 2014 6:01 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Another TreeView enigma
PostPosted: Tue May 13, 2008 5:48 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Guys. I have no idea why one code works and the other does not.
It DOES works when: In the tree creation I don't have g_object_unref(store) but all Gtk variable set to static.
It does NOT work when I have g_object_unref(store) in the fuction.
What is going on ?
Peter

Here is the code:
Code:
//  THIS WORKS: it does not have g_object_unref(store);
//  and the Gtk.. variables are set to static

void OkSignalTree(GtkWidget *window, int r) {
   static GtkListStore *store;
   static GtkTreeIter iter;
   static GtkWidget *treeview, *scrolled_win;
   static GtkCellRenderer *renderer;
   static GtkTreeViewColumn *column;
   static GtkTreeSelection *selection;
   static GtkTreeModel *model;
   int i, j, R, Ndata, click = 0, n;
   gchar edtext[80];

      treeview = lookup_widget (window, "Signaltree");
      model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
      Ndata = sizeof(SigNames)/sizeof(SigNames[0]);

      if (r==STARTUP) {
         NumSignals = 0;      
         NumSelSignals = 0;

               
         store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);

        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Signal", renderer, "text", SIGNAME_COLUMN, NULL);
         gtk_tree_view_column_set_resizable (column, TRUE);
        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
        
        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Selected", renderer, "text", SIGUNIT_COLUMN, NULL);
         gtk_tree_view_column_set_resizable (column, TRUE);
        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
         gtk_tree_selection_set_mode ( selection, GTK_SELECTION_MULTIPLE );

      //
                        {
            // insert content
         }
      }      
      gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
      gtk_widget_show_all(treeview);
}




// THIS ONE DOES NOT WORK!!! it has: g_object_unref(store);
// The Gtk varables are not static as in most examples
void BADSignalTree(GtkWidget *window, int r) {
   GtkListStore *store;
   GtkTreeIter iter;
   GtkWidget *treeview, *scrolled_win;
   GtkCellRenderer *renderer;
   GtkTreeViewColumn *column;
   GtkTreeSelection *selection;
   GtkTreeModel *model;
   int i, j, R, Ndata, click = 0, n;
   gchar edtext[80];

      treeview = lookup_widget (window, "Signaltree");
      model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
      Ndata = sizeof(SigNames)/sizeof(SigNames[0]);

      if (r==STARTUP) {
         NumSignals = 0;      
         NumSelSignals = 0;

               
         store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);

        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Signal", renderer, "text", SIGNAME_COLUMN, NULL);
         gtk_tree_view_column_set_resizable (column, TRUE);
        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
        
        renderer = gtk_cell_renderer_text_new ();
        column = gtk_tree_view_column_new_with_attributes ("Selected", renderer, "text", SIGUNIT_COLUMN, NULL);
         gtk_tree_view_column_set_resizable (column, TRUE);
        gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);

         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
         gtk_tree_selection_set_mode ( selection, GTK_SELECTION_MULTIPLE );

      //
                       {
            // insert content
         }
      }      
      gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
      g_object_unref(store);
      gtk_widget_show_all(treeview);
}




Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group