Re: g_signal_connect arguments
- From: Paul Pogonyshev <pogonyshev gmx net>
- To: franfernandezb coit es, gtk-app-devel-list gnome org
- Cc:
- Subject: Re: g_signal_connect arguments
- Date: Sun, 8 May 2005 22:30:20 +0300
franfernandezb coit es wrote:
Hi all,
I am new to GTK programming, and I've got a very simple question about
callbacks. In the application interface that I am encoding the next
function brings up a window containing several GtkEntries and a
GtkCheckButton to gather the options chosen by the user:
void menu_qdisc(){
..
GtkWidget *isRoot;
GtkWidget *entry1;
GtkWidget *entry2;
isRoot = gtk_check_button_new_with_label ("root qdisc");
entry1 = gtk_entry_new();
entry2 = gtk_entry_new();
..
g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (callback_create), ???);
The problem is that I don't know how to define the signal_connect function
as all the examples that I've found only pass one widget parameter to the
callback. Should I pass the window containing all the widgets as an
argument?
You should pass a pointer to a structure that will allow you to retrieve
all the data you need. If your window/dialog has its own class, then
pass a pointer to the window/dialog object. Else do something like
typedef struct _SomeDialogData SomeDialogData;
struct _SomeDialogData {
GtkWidget *isRoot;
GtkWidget *entry1;
...
};
Fill this structure (preferably g_malloc'ed) when you create the window
and pass it as your `user_data' as fourth parameter of g_signal_connect().
Then your callback can look like
void
callback_create (GtkWidget *button, SomeDialogData *data)
{
...
}
Since you probably don't need the pointer to the button, you can instead
connect using g_signal_connect_swapped() and simplify the callback to
void
callback_create (SomeDialogData *data)
{
...
}
And what is the way to read the user info from the widgets in the callback
function?
Depends. For text entries it's like gtk_entry_get_text (entry). (May need
to cast with GTK_ENTRY() if you are passing generic pointers to `GtkWidget'
around.) For check/radio/toggle buttons it is gtk_toggle_button_get_active().
Paul
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]