Re: [gtk-list] May be atrivial question



On Sat, Jan 08, 2000 at 08:14:29PM +0100, Mario Motta wrote:
> hi all,
> may be a trivial question:
> "if i connect to a widget to a signal trough a callback and later this 
> widget is destroyed, what happens to the connection if i do not 
> disconnect widget before his destruction ?"

As Havoc said, the right thing happens automatically.  But don't
forget that bad things can happen if your destroyed widget is being
used as extra data for a signal that another widget emits.

For example, if you want widget foo to do something whenever a button
is pushed, you'd probably do something like:

void clicked_cb(GtkButton* b, gpointer f_ptr)
{
  foo_function(GTK_FOO(g_ptr));
}

... stuff ...

  gtk_signal_connect(GTK_OBJECT(my_button), "clicked",
                     GTK_SIGNAL_FUNC(clicked_cb), foo);
 
... stuff ...

If foo gets destroyed without that signal being disconnected,
foo_function() will be called with the dangling pointer the next time
that the button is clicked.

The easiest solution is usually to call

  gtk_signal_disconnect_by_data(GTK_OBJECT(my_button), foo);

sometime before foo gets destroyed.  This is often more convenient
that saving the handle that gtk_signal_connect() returns.

I know this wasn't the original question, but this one has bitten me
a few times, and I was feeling pedantic...

-JT

-- 
COMINT secret | Jam Echelon! http://www.echelon.wiretapped.net | NSA explosives
assassin terrorist car bomb tactical bin laden waco white house nuclear clinton



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