[Glade-users] [glade-users] Using a global variable for 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






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