passing object(widgets) references: preferred way [gtkbuilder, g_object(set/get)_data, or..]



Dears,

I guess it is a beginner question. The problem is:

At a given point you have to set the text of a textbox
deep within your code. How do I retrieve the object?
Or better I do I set the object to be found?

The gtkbuilder option 1:
I use gtkbuilder and I globally store the *builder reference
so that I can always use:
gtk_builder_get_object(builder,"myobject")
[and free the builder only once I close the app]

The gtkbuilder option 2:
I use gtkbuilder and I set up a local function "mycode_reference_all()"
in the style of the old glade which was "g_object_set_data()" for every
entry and free the builder after allocation.

I guess that the difference is on one side the memory of the builder
and on the other a matter of style. At least for this simple picture.
In more complex cases I guess it is also a matter of sharing
information between parts of the code and OOP style stuff.
But I need you to teach me. Which one?

In this respect. What would be the difference if I set up a couple or more
structures to store the pointers instead to use a "g_object_set_data()"
to share the widgets references?
I partially answer my question:
We need a mechanism in order to create widgets which is consistent.
But why can't we do it implicit? I mean: lookup_widget(parent,"name").
It might be that it is already there... so sorry for double asking..

In any case: in my pretty simple apps I can work it out.
But what it will be the "best practice" for complex applications?

cheers
Fabio



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