GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

a newbie in need of concepts

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Dpux



Joined: 22 Jul 2008
Posts: 2

PostPosted: Tue Jul 22, 2008 6:29 am    Post subject: a newbie in need of concepts Reply with quote

i have just started programming in gtk,and i havent got any gui programmin experience till now, so pardon me if this question sounds too stupid :)
here is a snippet of the code i went through :

button=gtk_button_new_with_label("button1");
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(callback),(gpointer)"button1");
gtk_table_attach_defaults(GTK_TABLE(table),button,0,1,0,1);
gtk_widget_show(button);
button=gtk_button_new_with_label("button2");
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(callback),(gpointer)"button2");
gtk_widget_show(button);

i cant understand, why we have the same name "button" for two different buttons; this should create problem as button is a pointer itself and so changing it should change the widget created, and not the copy of the widget.how is this happening ??
Back to top
Vadi
GTK+ Geek


Joined: 28 May 2008
Posts: 68

PostPosted: Tue Jul 22, 2008 1:03 pm    Post subject: Reply with quote

button becomes another object when you create a button on it.
Back to top
Dpux



Joined: 22 Jul 2008
Posts: 2

PostPosted: Tue Jul 22, 2008 4:13 pm    Post subject: Reply with quote

yes it seems to me so. but i wanted to know the mechanism of creating the new button with the same name...
Back to top
Vadi
GTK+ Geek


Joined: 28 May 2008
Posts: 68

PostPosted: Tue Jul 22, 2008 5:39 pm    Post subject: Reply with quote

I think you're confusing the button name and a button label.

You cannot have two buttons with the same name, but you can have two buttons with the same label.
Back to top
dreblen
Never Seen the Sunlight


Joined: 14 Jun 2007
Posts: 538
Location: Falun, WI USA

PostPosted: Tue Jul 22, 2008 11:34 pm    Post subject: Reply with quote

you could (theoretically) use the same GtkWidget* variable for every widget in your program, because the gtk_*_new() functions just return a pointer to a newly created object,
although, you probably shouldn't really do that.

so to answer your question, the reason you can use the same variable is because the gtk_*_new() functions return a pointer,
it doesn't care what was held in the variable before
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP