antoyo antoyo - 1 year ago 112
C Question

Init GValue for a struct

I am trying to get a

from a
, but I am unable to init a
with such a type.

I tried the following code:

GValue value;
g_value_init(value, G_TYPE_OBJECT);
gtk_style_context_get_property(style_context, "color", STATE_FLAG_NORMAL, &value);

But I get the following error:

cannot initialize GValue with type 'GdkRGBA', the value has already been initialized as 'GObject'

I tried many of the other
, but I get a similar error.

How can I initialize a
with a type

Answer Source

Try removing the call to g_value_init altogether—judging by the error message it seems gtk_style_context_get_property wants to initialize the GValue on its own.

Also, I note there is a separate method defined on GtkStyleContext specifically for retrieving the foreground colour, so this may be a suitable (or preferable) alternative:

GdkRGBA color;
gtk_style_context_get_color(style_context, GTK_STATE_FLAG_NORMAL, &color);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download