Re: g_signal_connect ?



On Wed, 2004-03-31 at 22:42, ionut grigorescu wrote:
Hello !!!
I don't want to waste anybody's time so here's my
question :
When a button get's pressed I use g_signal_connect to
use a callback function, but I can only submit one
parameter to that callback functio.

In the user_data field of the function.

As example in a click event to pass the string "Hi" to the callback, you
can do:

GtkWidget* button;
....
g_signal_connect ((gpointer) button, "clicked",
                 G_CALLBACK (on_widget_clicked),
                "Hi");

The callback should be something like:

void
on_widget_clicked (GtkButton* button, gpointer user_data)

In the user data field you can get a pointer to the "Hi" string you
passed.

How can I send two
ore more parameters to that function ?

The same way.

typedef struct _params {
        gint field1;
        gint field2;
} t_params;

GtkWidget* button;
....
t_params params;

params.field1 = 0;
params.field2 = 1;

g_signal_connect ((gpointer) button, "clicked",
                 G_CALLBACK (on_widget_clicked),
                &params);

In the callback you can access them this way:

void
on_widget_clicked (GtkButton* button, gpointer user_data)
{
        t_params* p_params;
        p_params = (t_params*) user_data;

        g_print("params are field1=%d field2=%d\n",
                p_params->field1, 
                p_params->field2 );
}


Hope this helps.
-- 
Iago Rubio   
- Home page    * http://www.iagorubio.com 
- Last project * http://cssed.sourceforge.net         
- GPG Keyserv  * pgp.rediris.es id=0x909BD4DD

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]