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



Andreas Kotowicz wrote:
[...]
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?

This is a typical, popular and clean way to pass mulitple
variables/addresses to a callback, yes.

If you allocate a struct for that a g_signal_connect time...
you might want to consider useing something like
g_object_weak_ref() to free your struct when the button you
connected to is finalized (maybe there is a g_signal_connect_data_full
variation that does this for you ?).


Cheers,
                         -Tristan




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