Posted: Sun Apr 29, 2007 7:33 pm Post subject: Update a label
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 :)
Joined: 21 Sep 2005 Posts: 386 Location: Fairfax, Virginia
Posted: Sun Apr 29, 2007 11:31 pm Post subject:
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:
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*).