GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Oct 26, 2014 4:27 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Update a label
PostPosted: Sun Apr 29, 2007 7:33 pm 
Offline

Joined: Sun Apr 29, 2007 7:07 pm
Posts: 3
I'm in the process of making a frontend from one of my programs (written in C). The program sends data to the parallel port. I've split the program up into several pieces. main() is where I do the widget making and so on.
If the user wants to send something, they enter a number into a text field, and hit the "send" button. When they do this, the data from the text field is sent to a function, which I made, that sends the data to the parallel port. From within the function that handles the data sending, I'm using g_print() to sort of echo back to the user what data was sent. But g_print only echo back to the terminal. What I want to do it add an extra feature that will echo it back to a label also.

How would I do this? A nice simple example would be great :)

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 29, 2007 11:31 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
So, let's say you have you GtkButton and your GtkLabel. You have to connect the button to the "clicked" signal to handle the click. In your main function, do this to connect it:

Code:
g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (button_clicked), (gpointer) label);


In this signal connection, you are passing the GtkLabel as the fourth parameter of g_signal_connect(). You can then use the following callback function:

Code:
static void
button_clicked (GtkButton *button, gpointer data)
{
  GtkLabel *label = GTK_LABEL (data);
  /* Do whatever you want here, using the label ... */
}


If you are already passing something in the user data parameter, consider creating a structure that holds the label and your data. You can pass that structure to the callback function, since gpointer is just a void pointer (void*).

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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