On 01/31/11 16:39, James Morris wrote:
> On 31 January 2011 13:32, Jannis Pohlmann <jan...@xfce.org> wrote:
>
>>> Can anyone point me in the direction of code examples where the
>>> construction of the g object requires a parameter so I can see how to
>>> do it please? - I can't make sense of the documentation.
>> I usually do this by adding a construct or construct-only property to
>> the object class and creating a my_object_new() function that takes a
>> parameter for this property that I can then pass to g_object_new().
>>
>> Here's a simple example from Xfce's XDG menu library garcon: GarconMenu
>> is the object and it needs a menu file (a GFile object) to be
>> constructed properly. So what we did is to to install a construct-only
>> property like this:
>>
>>  http://git.xfce.org/libs/garcon/tree/garcon/garcon-menu.c#n246
> It looks straight forward at first glance but soon becomes apparent
> it's not at all :/
>
> I want to pass a const char** null terminated list of C strings -
> which is obviously not a G_TYPE_FILE!
> I thought maybe I could use G_TYPE_ARRAY but that results in:
>
> GLib-GObject-CRITICAL **: g_param_spec_object: assertion `g_type_is_a
> (object_type, G_TYPE_OBJECT)' failed
>
> So I've no idea what to do there. It's as clear as mud; I'm a GObject newb.
>
>
>> and write a _new() function that takes a GFile for this property and
>> passes it to g_object_new():
>>
>>  http://git.xfce.org/libs/garcon/tree/garcon/garcon-menu.c#n459
>>
>> This property will not be available in the init function (e.g.
>> garcon_menu_init) but if you want to do something with it before the
>> object can be used by the outside world, you can do that by overriding
>> the GObject constructed function like you do with finalize or
>> get_property. In constructed, the construct and construct-only
>> properties will be set and you can do something with them.
>>
> Anyway, thanks for making an effort to help.  I think the only way
> anyone could provide any further help here would be to show me an
> example that works using a const char ** null terminated list of c
> strings as a parameter to the constructor.

Use gpointer or a gboxed.

Stefan
> I will most likely avoid GObject all together and do it the old
> fashioned C way as this only seems to be making it more complex than
> necessary.
>
> Thanks,
> James.
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to