[Glade-users] Question



Alef T Veld wrote:

One question remains though, do i need to get all the widgets i need in the future
in other functions upfront and make them global, or can i do a glade_xml_get_widget
in a function, then populate (for example, a combobox) it, and expect it to show
once i close and recall that particular function (or a different one referring to that
combobox?)

I suspect i have to either make them global or start passing variables.

~alef~

Hmm, its an interesting question for me too, so I'm cc'ing "glade-users"
list (maybe this message will hang that damned anti-spam tool ?! ;] ).

Some time ago I never bothered myself with global variables - when I
needed the pointer to widget I just call glade_xml_get_widget().
libglade uses hash table for each GladeXML object, so it finds widget
reasonably fast.

Some time after I decided that wasting CPU time (even so small, but not
so really small for big string hashes) is not a good idea and started to
use globals, initialized almost after glade_xml_new() call (under global
I mean 'static' global variables visible only per C module). But when
the number of widgets increases - its became harder to maintain the module.

Now I'm using hacks like this:
static void local_function(GladeXML *xml)
{
static GtkWidget *widget=0;
     if (!widget) {
         widget = glade_xml_get_widget(xml, 
"the-widget-i-want-to-use-here");
         g_return_if_fail(widget!=NULL);
     }
     ...
}
Its easier to deal with module with such an approach for me. The single
hash lookup needed, variable is visible in function scope only.

It would be interesting to hear comments and suggestions from list...

     Olexiy







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