Re: what's the best way to handle variables and objects?



You can create a generic struct but more often than not there is an
application object or struct that the application developer creates
which holds all the public variables he or she would care about which is
passed as userdata to things like g_signal_connect.  

BTW GtkObject is usually not used directly anymore.  Usually objects are
passed to callbacks as GObject, GtkWidget or their actual class (in your
case GtkButton) as they are the most useful casts. 

On Wed, 2006-03-15 at 19:18 +0100, Andreas Kotowicz wrote:
I'm looking for a clean solution on passing variables and objects from
gtk calls to callback functions and back.

I call for instance

g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(clear_timer_cb), progressbar);

and pass with it the object I'm working with. (progressbar has been
definded before: GtkWidget *progressbar = gtk_progress_bar_new(); )

now in clear_timer_cb I can modify the object:

void clear_timer_cb(GtkObject *window, void *data)
{
  GtkWidget *progressbar = data;
  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), 0);
}


but what should I do if I want to modify any other variables in this
function as well? let's say that in the part where I created the
g_signal_connect there are also some variables A and B which might be of
interest in clear_timer_cb. 

should I create a struct

struct data {
  gdouble *A;
  gdouble *B;
  GtkWidget *progressbar
};

and then initiate it and pass it always on?

what's the best way in dealing with this?

cheers,
Andreas

_______________________________________________
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]