I am writing a GTK+ application in C (though the principle here is widely applicable) which contains a GtkComboBox. The GtkComboBox is part of a larger structure returned by another function and packed into the main window.
I don’t see how I can get the value of what is selected in the GtkComboBox other than by setting a global variable from its callback function. Or is there still some way of referring to the GtkComboBox later in the program, outside of the function which declared it?
Or should I not be declaring it inside a function (other than main( )) in the first place?
If the function that declares a stack variable in C has returned, that variable is no more. If you need GtkComboBox (or other object) to persist, you have a few options:
I would probably go with the malloc/pass around a pointer approach, but can’t be sure without more knowledge of your situation.