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 

Update a label

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



Joined: 29 Apr 2007
Posts: 3

PostPosted: Sun Apr 29, 2007 7:33 pm    Post subject: Update a label Reply with quote

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.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Sun Apr 29, 2007 11:31 pm    Post subject: Reply with quote

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: (Plaintext)
1
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: (Plaintext)
1
2
3
4
5
6
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*).
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