Arguments in GObject-based object constructor



Lets say I've written an abstract class Foo (a class that is not supposed to be instantiated), and a class that inherits from Foo called Bar, which is instantiable. Foo takes 2 constructor arguments/properties "x" and "y". Bar:s constructor takes the samt arguments. In order to initialize some of Bar:s attributes, it needs to know both "x" and "y". In the bar_init() function I can't get the "x" and "y" properties, because they arent set yet, so where do I initialize the attributes? Should I hook into the get/set property of both "x" and "y", and once both are set (check with some boolean variables), I can initialize them in bar_set_property() ?
That way sounds a little too complicated so I think I'm missing something.

The GObject documentation states:

static void
maman_bar_init (GTypeInstance   *instance,
               gpointer         g_class)
{
 MamanBar *self = (MamanBar *)instance;
 self->private = g_new0 (MamanBarPrivate, 1);

 /* initialize all public and private members to reasonable default values. */
 /* If you need specific consruction properties to complete initialization,
* delay initialization completion until the property is set. */
}

What does it mean by "delay initialization completion until the property is set" ?

Regards Jacob Kroon



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