GtkTreeView : some questions

Hi all,

I'm having some troubles with GtkTreeViews. Here the description:

-I have a complex object/structure to render in a GtkTreeView, using
a GtkListStore. The object can have several fields, but the view
should display only 3 text columns (converted from the data in the struct).

Ex :

typedef myStruct {
   int col1;
   double col2;
   double col3;

To render this as strings I made custom translation functions like:

treeview_constant_set_name (GtkTreeViewColumn *tree_column,
               GtkCellRenderer   *cell,
               GtkTreeModel      *model,
               GtkTreeIter       *iter,
               gpointer           data)
 myStruct *my_object;
 gtk_tree_model_get (model, iter,
                     0, &my_object,
   //convert the long to a string here
   gchar *myString = ...;

  g_object_set (GTK_CELL_RENDERER (cell),
               "text", myString,

my model is hence defined as:

GtkListStore *model = gtk_list_store_new (3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER);

where the pointer is a pointer to a dynamically allocated instance of the struct.

What's the problem? Well, this *almost* works. When adding new lines to the model, most of the time the lines are rendered properly. But sometimes (randomly), the pointer returned by gtk_tree_model_get seems to be just garbage. Results vary from a weird string to
an application crash.

This really looks like a memory corruption problem, but I have not found (yet) a problem
in my code. So I'd like to know:

-If this is the right way to proceed (using pointers in the model...)
-If this is the right way, I can provide a sample source code to show the problem.

Thank's everybody!


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