Re: Pass more widgets as gpointer.



Hi, Jens

Yes, your way is good (thank you for a small code, maybe I will use it
in my projects). But, are you sure your way is safe?
You don't know the size of array (at the first),
where do you free the array of pointers itself (try g_malloc and
g_free, because it is GLIB :) ) (at the second).
And I think, your way isn't type-safe (at the third), because you
won't be sure that your element's type is needed.
Well, of course I have many questions and now answers :) I think, in
small projects your way is good (but you can also easily forget the
order of the elements). Maybe HashTables, or STL sets will be more
applicable.

What do you think about all of this?

Good luck in GTK programming :),
Vlad Volodin

2009/4/22 Jens Hansen <jensh604 gmail com>:
Hi All.

Thanks for all ideas, to this problem. I figured out how to pass more
widgets in an array, which is IMHO the best way to do it. Just for
reference, the following snippet.

"Packing" the widgets pointers in the array
ÂGtkWidget * *data;
Âdata = malloc(sizeof(GtkWidget *)*3);
Âdata[0]=spinbutton;
Âdata[1]=combobox;
Âdata[2]=check_hidden
And "unpacking" them
GtkWidget * *array=(GtkWidget **)data;
Then you just need to type cast the elements of the array:
for instance
Âgtk_combo_box_get_active((GtkComboBox *)array[1])
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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