Re: gtk_signal_connect order



Hi,

Ignacio Nodal <inodal teleline es> writes:

> I've got some problems to understand in which order the signals are
> connected to an object. Reading the tutorial I understood that if an
> event have several callbacks they would be executed in the order they
> where connected.
> 
> I mean.. I've got a class and the contructor of this class includes
> these lines:
>  
>   gtk_signal_connect (GTK_OBJECT(_pwindow), "delete_event",
>                       GTK_SIGNAL_FUNC(gtk_widget_destroy), NULL);
> 
>   gtk_signal_connect (GTK_OBJECT (_pwindow), "destroy",
>                       GTK_SIGNAL_FUNC(gtk_widget_destroy), NULL);

If you are deriving from GtkWidget, you don't want to connect to the
widgets signals in your derived class. That would mean to connect to
your own signals which works, but does not make much sense. Instead
implement the delete_event method in your derived class. To do so, 
you'd write in
foo_class_init (FooClass *klass)
{
  GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;

  widget_class->delete_event = foo_delete_event;      
}

Then in foo_delete_event, do whatever you like to happen on delete_event.
Since the delete_event signal is of type GTK_RUN_LAST, foo_delete_event 
will be run after the connected user-defined handlers (unless they are 
connected using gtk_signal_connect_after).

Connecting gtk_widget_destroy to your own destroy signal is useless and
a bad idea that you should simply drop (see below).

> In my main.cpp i've got this other lines:
> 
>  NewParamWindow = new ParamWindow(widget);
>  
> gtk_signal_connect(GTK_OBJECT(NewParamWindow->GetWidget()),"delete_event",
> 		     GTK_SIGNAL_FUNC(local_delete),NULL);
>   gtk_signal_connect(GTK_OBJECT(NewParamWindow->GetWidget()),"destroy",
> 		     GTK_SIGNAL_FUNC(local_delete),NULL);
> 
> If a destroy event happens.. isn't it suppose to be the
> gtk_widget_destroy callback to be executed first?

Do not confuse yourself and others by mixing events and signals. You 
are speaking about the destroy signal being emitted here. There's a 
destroy_event too, but that's a different thing.

> It was connected first by the constructor in the "NewParamWindow = new
> ParamWindow(widget);" line, wasn't it?

Yes, but the destroy signal is emitted after the object has been marked 
as being destroyed. Therefore your call to gtk_widget_destroy simply 
does nothing at all.

> The fact is i really want to execute first my local_delete callback, as
> it does, but i don't understand why it's working.

I suggest you start by reading Havoc's book which explains this stuff 
quite nicely. Get a copy or read it online at 
http://developer.gnome.org/doc/GGAD/


Salut, Sven




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