Re: problem with gtk_signal_connect_object




Stefan Wille <wille@netlife.de> writes:

> robert havoc pennington wrote:
>  
> > gtk_signal_connect_object() doesn't actually do anything to the
> > "receiver," I don't think, you could actually use any pointer you want
> > there, or even NULL. The pointer is simply stored and passed to the
> > callback.
> 
> Yes, it seems to be like that. But I think it should be different, 
> gtk should take care connections to deleted objects,
> since it knows that the connection goes to a GtkObject.
> 
> > If you need to remove a callback, you can save the return value of
> > gtk_signal_connect and use that to remove the callback at a later time.
> 
> I could do this, but I think gtk should do that for me. In Qt (don't
> flame me)
> it works the same - if you connect to an object and then delete the
> object,
> the connection gets disconnected.

I think you are assumming to much about gtk_signal_connect_object().

It doesn't do any special "object" magic for its fourth parameter.

guint  gtk_signal_connect_object	  (GtkObject	       *object,
					   const gchar	       *name,
					   GtkSignalFunc	func,
					   GtkObject	       *slot_object);

simply means is pass slot_object as the first parameter to func, instead
of object.

You can currently write:

 gtk_signal_connect_object (object, "destroy",
                            GTK_SIGNAL_FUNC (g_free),
                            GTK_OBJECT (some_data_associated_with_object));

So changing this could (and probably would) break existing code. 


Also, the extra bookkeeeping for keeping track of _object()
connections I don't think is worth the benefit of the rare case when
want destroy the object early.

Currently, you just have to write:

 gtk_signal_connect_object (GTK_OBJECT (object1), "signal",
                            GTK_SIGNAL_FUNC (callback), GTK_OBJECT (object2));
 gtk_signal_connect (GTK_OBJECT (object2), "destroy",
                     GTK_SIGNAL_FUNC (gtk_signal_disconnect_by_data),
                     object1);

Regards,
                                        Owen



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