Re: Question about entry callbacks
- From: Havoc Pennington <hp redhat com>
- To: Vicki Stanfield <vicki dialupnet com>
- Cc: GTK-List <gtk-list gnome org>
- Subject: Re: Question about entry callbacks
- Date: 15 May 2001 22:31:22 -0400
Vicki Stanfield <vicki dialupnet com> writes:
> I am trying to create a callback for an entry widget. When a string
> is typed in, I want the callback to be called. I assume that I can
> use the entry widget which is passed in with the gtk_entry_get_text
> function to get the string. The problem is that when I try to compile,
> I get an error which doesn't make sense to me. The code is based on the
> example at http://www.gtk.org/tutorial/sec-textentries.html
>
> My call looks like this:
>
> entry_widget = gtk_entry_new_with_max_length(35);
> gtk_signal_connect_object (GTK_OBJECT(entry_widget), "activate",
> GTK_SIGNAL_FUNC(GetAccountName), entry_widget);
The warning you get is because the last arg to connect_object has to
be cast to GtkObject with the GTK_OBJECT() macro.
Though, rather than adding that cast, I would suggest abandoning all
use of gtk_signal_connect_object(). It is an evil, confusing,
nonsensical function that causes endless confusion judging by
questions on this list. Just pretend it does not exist and you will be
happier. ;-) It is purely a way to save typing; it is never required
in order to achieve a given result.
> void GetAccountName(GtkWidget *widget, GtkWidget *entry_widget)
With connect_object, the callback should be:
void GetAccountName (gpointer user_data, GtkWidget *widget_emitting_signal)
With plain connect(), the args are in their normal order:
void GetAccountName (GtkWidget *widget_emitting_signal, gpointer user_data)
i.e. connect_object basically just swaps the args. It also requires
the user data to be a GtkObject, but there is no rational reason for
that.
Though the order changes, the first and last args to a callback are always the
object that emitted the signal (in this case the entry) and the user
data passed to connect() or connect_object().
If a signal has any additional args, such as the event arg to
button_press_event, then those args go in the middle between the
emitting object and user data.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]