GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Nov 22, 2014 2:23 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Gtk change multiple labels on button click
PostPosted: Mon Oct 07, 2013 9:23 am 
Offline
Familiar Face

Joined: Tue Oct 01, 2013 6:37 am
Posts: 10
How can i change multiple label values on single button click.Normally on a button click signal connect we can give only one user data. Example code

Code:
void show_loop(GtkWidget *widget, gpointer user_data)
{
    char buf[5];
    int no = TxBuf.plBuf[7];
  sprintf(buf, "%d",no);
  gtk_label_set_text(GTK_LABEL(user_data), buf);
}

ID_label=GTK_WIDGET (gtk_builder_get_object (builder, "label24"));
DLC_label=GTK_WIDGET (gtk_builder_get_object (builder, "label25"));

check = GTK_WIDGET (gtk_builder_get_object (builder, "button3"));
g_signal_connect (check, "clicked", G_CALLBACK (show_loop), DLC_label);


I want to change both the labels on single button click.


Top
 Profile  
 
 Post subject: Re: Gtk change multiple labels on button click
PostPosted: Wed Oct 09, 2013 5:54 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 777
Location: UK
Hello,

There are two ways to deal with this.

- Use global variables, this is not recommended as when your application grows you can loose track of what variable does what and the code will become messy

- Use structures. This way you can pass pointers to the structure with all variables related to a window instance in one place.

Another note about your code is that it is unsafe and has a flaw in it. You use the function sprintf() with out setting any bounds which could mean you have a buffer overflow. Can you definitely say that your integer will never ever be greater than 9999?

_________________
E.


Top
 Profile  
 
 Post subject: Re: Gtk change multiple labels on button click
PostPosted: Wed Oct 09, 2013 6:04 am 
Offline
Familiar Face

Joined: Tue Oct 01, 2013 6:37 am
Posts: 10
Yes i limited the size in glade i configured maximum length to two.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group