[Glade-users] [glade-users] Using a global variablefor GladeXML object?
Alexey Kurochkin
alexey.kurochkin at pathfinderlwd.com
Fri Jan 19 13:03:02 EST 2007
I could be wrong, but I believe the GladeXML object is still there, even
if you aren't referencing it no more, until the last widget created by
it is destroyed; and you can get the reference back with
glade_get_widget_tree function. Am I wrong? At least "XML parse tree is
cached to speed up creating another GladeXML object for the same file"
as Libglade manual says in glade_xml_new function description. But of
course keeping individual references for most used widgets is more
efficient anyway.
Alexey.
-----Original Message-----
From: glade-users-bounces at lists.ximian.com
[mailto:glade-users-bounces at lists.ximian.com] On Behalf Of Tristan Van
Berkom
Sent: Friday, January 19, 2007 9:56 AM
To: email at micahcarrick.com
Cc: Glade Users
Subject: Re: [Glade-users] [glade-users] Using a global variablefor
GladeXML object?
On Fri, 2007-01-19 at 00:33 -0800, Micah Carrick wrote:
> When I create my applications using glade, I create and use the
gladeXML
> object in an initialize function and store all references to widgets I
> will need later in a structure declared in main(). I pass the
necessary
> widgets to callbacks, and then I call g_object_unref() on the gladeXML
> object and return. I do this mainly because I try to avoid global
> variables because that's what I learned somewhere along the way.
>
> I see that a lot of people simply declare the gladeXML object as a
> global variable and use glade_xml_get_widget whenever they need to
> access a widget throughout their code.
>
> I'm curious as to what people's thoughts are on this? Is there a
> "conventional" way? Are there major drawbacks to the latter?
Your original method is sound - carrying a GladeXML object around
is pointless since it consumes a considerable amount of ram (i.e.
an interpreted glade file in data structures + hashmap of widget
names etc)...
Personally I think storing pointers to the widgets you need at
initialization time is best - but there is also another option,
you can write a lookup_widget_by_name() function that recurses
through the hierarchies of all toplevels searching for the widget
by its name (this is a little suboptimal but maybe makes your
code simpler).
Cheers,
-Tristan
_______________________________________________
Glade-users maillist - Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
More information about the Glade-users
mailing list