[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Google
  Web www.spinics.net

g_signal_connect question



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?


thank you for reading
:)
DsP
_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[GIMP Users]     [Yosemite News]    [Yosemite Photos]    [Gimp's Home]     [Steve's Art]

Add to Google Powered by Linux