Re: Using global variables for widgets



    Technicly useing global variables can cause namespace
problems when you give them simple names such as "widget". also 
if your writing a library; you probably dont want theese variables
to be exported to the applications that link with it (more
namespace problems). ofcourse this doesn't mean that you shouldn't
ever use global variables.

here is one of the many ways to avoid globals in your case:


void main() {


GList *hide_data = NULL;

for (all widgets to hide)
   hide_data = g_list_append(hide_data, widget)

g_signal_connect(G_OBJECT(button), "clicked",
                 G_CALLBACK(hide_widgets), hide_data);    

...

}


hide_widgets(...user_data) {

  GList *list = user_data;

  while (list && list->data) {
     GtkWidget *wid = list->data;
     gtk_widget_hide(wid);
     list = list->next;
  }


}


you can also check out the docs for g_object_set_data()
for another flavor of pointer references and ofcourse
you can choose structures instead of doubly linked lists.

Hope this helps,
        -Tristan



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