Re: two or more objects into a signal handler



Gonzalo Aguilar <gad reymad com> writes:

How can I pass two objects to a signal?


I'm trying to make a button unclickable if a entry text box is empty, so
I use the change event on the entry box to
check if the entry box is empty and if so, then I make the button
unclickable...

But then I need the entry box and the button in the signal handler, but
I only can pass one argument...
The entry box to check if it's empty, and the button to make it
unclickable...

How can I make this operation?

Should I use a structure to pass the pointers to the objects?

Thanks for your help...
Please answer to my e-mail too.


The entry_changed signal handler has two arguments:

on_entry_changed (GtkEditable     *entry,
                  gpointer         user_data);

First is the GtkEntry that has changed, second is the user data
given by the signal_connect().
So you dont need to pass two arguments in this case.

Yes, but I WANT to pass two OBJECTS to my handler...

If the entry passed in is not the entry you want, you need to create a
struct to pass in as user_data, or set the data on the object.  You can
do this by doing something like:

gtk_object_set_data (GTK_OBJECT (entry), "myobject1", object1);
gtk_object_set_data (GTK_OBJECT (entry), "myobject2", object2);

...

later in the callback:

GtkObject *object1 = gtk_object_get_data (GTK_OBJECT (entry), "myobject1");
GtkObject *object2 = gtk_object_get_data (GTK_OBJECT (entry), "myobject2");


Thanks,
-Jonathan




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