Re: Finding a widget in a Glade interface



Jim George wrote:
I should have mentioned that by time I want to call
glade_xml_get_widget() the GladeXML *xml created by xml =
glade_xml_new("filename.glade", NULL, NULL); is out of scope.  If I call
 open the file again to get the widget it has no affect on the running
window.  I need to get the widget from the running window from some
callback.  Any ideas?
Make 'GladeXML *xml' static or otherwise accessible from all parts of the
sourcecode.

tom


Not a good idea. I had a similar question some time back, the xml
structure returned by glade_xml_new is too "heavyweight" to be
retained for a long time by your program, and it contains no useful
information aside from being able to pull out pointers to widgets. A
more apt way to do this would be to store pointers to all the widgets
you need soon after glade_xml_new (perhaps as members of a struct),
then dereference the GladeXML object. When you set up your callbacks,
have this structure passed as the "user" pointer. Now all callbacks
have access to the widgets in your window.

In addition to the examples posted earlier, you can also download the
source to any standard gtk program for additional examples. I used the
devhelp source for this.
-Jim

I wasn't a fan of keeping the GladeXml object around due to the resources it used. Even though it's not as efficient as storing pointer, I wish I could just traverse up and down the the object tree for my pointer. I guess I'll be storing the pointers that I need. That would mean that after calling glade_xml_new() I need to call glade_xml_get_widget() on each object I will need and then save that pointer . . . right?

Thanks,

dave



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