Reputation: 3447
How do I g_print
a GValue
, if I don't know it's type at compile time?
Is there some kind of special format character for the g_print
format string?
Upvotes: 0
Views: 941
Reputation: 3447
You can use g_strdup_value_contents
:
gchar * strVal = g_strdup_value_contents (&gvalue);
g_print ("gvalue: %s\n", strVal);
free (strVal);
Upvotes: 2
Reputation: 5705
Depends what format you want to print it in. If you don’t really care about the format, you can use g_value_transform()
to convert the value into a second GValue
which has been initialised with type G_TYPE_STRING
.
If you do care about the format, you will need to have a multi-branch if
statement which compares the value of G_VALUE_TYPE()
for your GValue
against many different GType
s. In the body of each if
block you’d have type-specific printing code.
Upvotes: 2