Re: using properties in gobject instance_init



On Thu, 2004-07-08 at 16:42 -0400, Steve Feehan wrote:
> I hope this is the correct forum for this question...
> 
> For example, the object is created:
> 
>     g_object_new(FOO_TYPE, "name", "Steve", NULL);
> 
> In the instance_init function for type Foo I would like to use
> this property. But it appears that the set_property function
> is called after instance_init.
> 
> Is this correct? If so, how can I use properties when
> constructing the object?
> 
> Thanks.

The order of functions called when creating a GObject is:

base_init() [called once]
class_init() [called once per class/subclass]

constructor()
 +- In this func must chain to parent first, to actually allocate the
object. That calls
 +-> instance_init()
 +-> set_property() for G_PARAM_CONSTRUCT properties.
 +- Then your constructor code, which comes after the chain-to-parent
call.

set_property() for non-CONSTRUCT properties.

So the easiest way is to have your properties declared as
G_PARAM_CONSTRUCT properties, and create the things which use those
properties in the my_obj_constructor() function.

James M. Cape

Attachment: signature.asc
Description: This is a digitally signed message part



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