Re: Retrieving value from GValue

On Saturday 31 January 2004 10:07, Chris Seaton wrote:

When I use gtk_tree_model_get_value I get a GValue. Looking through the
documentation of GValue I can't see any function for actually getting
the value (an int in this case) out of the GValue structure, apart from
g_value_peek_pointer but this isn't a pointer and that function is
marked for internal use anyway. I presume that I have to use a function
to get the actual value, as GValue is described as being opaque.

What do I do? 

Just don't use gtk_tree_model_get_value(), use gtk_tree_model_get() instead:

(here one column is of type G_TYPE_UINT and the other one is G_TYPE_STRING)

   guint    age;
   gchar  *name;
   gtk_tree_model_get(model, &iter, COL_AGE, &age, COL_NAME, &name, -1);
   g_print("Name is %s and age is %u\n", name, age);

If you really want to use GValues, it should work like this (I think):

   GValue  value_age = { 0, };
   GValue  value_name = { 0, };
   gtk_tree_model_get_value(model, &iter, COL_AGE, &value_age);
   gtk_tree_model_get_value(model, &iter, COL_NAME, &value_name);
   g_print("Name is %s and age is %u\n",


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