Re: g_signal_connect question
- From: David Malcolm <dmalcolm redhat com>
- To: deepspace <dsp edu physics uoc gr>
- Cc: gtk-list gnome org
- Subject: Re: g_signal_connect question
- Date: Tue, 03 Aug 2004 21:50:07 -0400
On Wed, 2004-08-04 at 04:37 +0000, deepspace wrote:
> Hi ;)
> I am having a strupid problem here , and i hope someone will take the
> time to help me out
> i know what i am doing is wrong but i can't find the right way to do it.
> look at the code
>
>
> struct args{
> gint numdice;
> gint sides;
> };
>
> void roll(struct args * p)
> {
> g_print("IN FUNC sides is %d \n",p->sides);
> }
> int main(int argc, char *argv[])
> {
> GtkWidget *window;
> GtkWidget *button1;
>
> struct args arg,*p;
> arg.numdice=(gint)1;
> arg.sides=(gint)10;
> g_print("sides is %d\n",arg.sides);
>
> p= &arg;
> g_print("sides by pointer is %d\n",p->sides);
>
> gtk_init(&argc,&argv);
>
> window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> button1= gtk_button_new_with_label("button1");
>
> g_signal_connect(GTK_OBJECT(button1),"clicked",GTK_SIGNAL_FUNC(roll),p);
>
> gtk_container_add (GTK_CONTAINER(window),button1);
> gtk_container_border_width(GTK_CONTAINER(window),15);
> gtk_widget_show(window);
> gtk_widget_show(button1);
>
> //main loop
> gtk_main();
>
> //end
> return 0;
> }
>
> ok , so until the gtk_main arg.sides is 10 as it should be ...
> but upon the start of the application , when i click the button and
> roll() is called p.sides becomes 7 and p.numdice 1035929
> why?
> how can it be fixed?
> isn't this the way to pass arguments to the function through
> g_signal_connect?
Your callback function needs more arguments; it needs to be something
like
void roll (GtkButton *button, struct args *p);
Look up the documentation for the signal you're connecting to get it
exactly right.
Currently the values you're seeing are due to the GtkButton object being
treated erroneously as a struct args
>
> thank you for reading
> :)
> DsP
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]