Re: dynamic gtk_list_store



On Monday 14 June 2004 00:15, John Coppens wrote:

Yes - and I'm not even sure how to destroy the old store either,
without creating a memory leak. I think I found most of the tutorials and
examples on the web, but none resizes the data store, or even destroys it.

The store is a GObject and is freed/destroyed when its refcount reaches zero. 
When you create a new list store with gtk_list_store_new(), it has a refcount 
of 1. When you set the model on a GtkTreeView, the tree view will add its own 
reference. So you basically need to do 

  store = gtk_tree_view_get_model (view);
  gtk_tree_view_set_model (view, NULL);
  g_object_unref (store);

The second line will make the treeview drop its reference to the store 
(instead of NULL you can also use another store there), and the third line 
will get rid of the initial reference from gtk_list_store_new().


If you want a data store with a dynamic number of columns, you'll have to 
write your own custom model that supports that I guess.


Alternatively, you could just use a list store with a G_TYPE_POINTER column or 
so, and store a custom struct there for each row, e.g.

struct _FooRow
{
    ... dynamically-allocated array that you can resize on-the-fly ....
};

Then use one or multiple cell data functions and retrieve the data for the 
column you need from the struct there.

Cheers
 -Tim



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