Re: Gtk signal_connect problem



On Thu, Mar 23, 2006 at 04:05:42PM +0100, hm wrote:
> I would like to write simple application in gtk. There is a button defined in main () function. I`m connecting a signal function, with an clicked-event as follows :
> 
> gtk_signal_connect ( GTK_WIDGET ( ShitButton ), "clicked", GTK_SIGNAL_FUNC ( ReceivedLoad ), (gpointer)(Labelz) );

It should be
g_signal_connect(ShitButton, "clicked",
                 G_CALLBACK(ReceivedLoad), Labelz);

(and please rethink your variable naming)

> The last parameter is a type cast from GtkWidget * Labelz[10] to a gpointer. I need it, because I want a ReceivedLoad function, to create ten new labels. Here is a ReceivedLoad function : 

It Labelz is an automatic array created on stack, it won't
work, because it won't exist anymore when the callback is
called.  (But even if it isn't an automatic variable it still
won't work for the reasons below.)

> gint ReceivedLoad ( GtkWidget * w, gpointer * p, gpointer ** Labelz ) 

This is not the prototype of "clicked" callback.  See the
API reference:
http://developer.gnome.org/doc/API/2.0/gtk/GtkButton.html#GtkButton-clicked

You will get Labelz as p and random piece of stack as
Labelz.

> Everything is going right, but when the function is going to return from signal call, program crashes with Segmentation fault.

Everything is going right until anything is affected by the
fact stack (probably including function return address) was
overwritten with junk.

Yeti


--
That's enough.



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