Re: g_object_get_property() with unknown type



The value type is a fixed part of each property, so in normal code you
should know the property type by looking at the property docs.

Well, but if you want to do something that requires introspection
capabilities I can point you on g_object_class_find_property().

Am Montag, den 31.12.2007, 17:30 +0100 schrieb ole nielsby pils org:
> Given a GObject* and a property name, what are the steps
> required to extract the property inty a GValue, not
> knowing its type beforehand?
> 
> It seems I can only make g_object_get_property work if
> I set the type of the GValue before the call.
> 
> This code works when the property is string-valued:
> 
> 	GValue v = {0, };
> 	g_value_init(&v, G_TYPE_STRING);
> 	g_object_get_property(object, name, &v);
> 
> - but is it not possible to initialize the GValue in a
> manner so that  g_object_get_property()  can switch to
> the appropriate type?
>
Don't think so.

> I tried with G_TYPE_INVALID and G_TYPE_NONE but this doesn't
> work.
>
You could patch glib/gobject/gobject.c and send that patch to Bugzilla,
if you can explain, why that feature is useful and worth the overhead.

> If I really do need to walk the type information, what are the
> steps required to find out the type and initialize the GValue?

As written above: g_object_class_find_property().

Ciao,
Mathias
-- 
Mathias Hasselmann <mathias hasselmann gmx de>
Openismus GmbH: http://www.openismus.com/
Personal Site: http://taschenorakel.de/

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



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