Re: Verifying input data before gtk_dialog_run returns




How is this all connected to the topic of the thread?

On Thu, Mar 22, 2007 at 01:27:29AM +0100, G Hasse wrote:
What you should do is 


void enter_callback(GtkWidget *widget, GtkWidget *entry)
{

  gchar *entry_text = NULL;
  entry_text = gtk_entry_get_text(GTK_ENTRY(entry));
 
  // Check to se what the entry contains...
  printf("the entry: %s\n", entry_text);


}

main()
{

  ....


  entry = gtk_entry_new();

  g_signal_connect(GTK_OBJECT(entry), "key-press-event",
                   GTK_SIGNAL_FUNC(enter_callback),
                   entry);

}

The callback protoype is wrong, it should be

  static gboolean
  entry_callback(GtkWidget *entry, GdkEventKey *event, gpointer user_data);

Typecasting the first g_signal_connect() argument with
GTK_OBJECT() does not improve anything.

Passing the entry again as the last argument of
g_signal_connect() is useless -- why would you want to get
the entry passed to entry_callback() as both the first and
the last argument?

Handling GtkEntry "key-press-event" yourself is not what one
normally wants (see the next point).

The entry gets the actually typed text in input method's
"commit" callback, called well after your key press handler,
so you can never see the actual text there.

GtkEditable has "changed" signal that allows to immediately
react to the changes.  It has "insert-text" and
"delete-text" signals too.

BUT! I get a segmentation fault at gtk_entry_get_text(GTK_ENTRY(entry))
that I dont understand...

This is caused by the prototype being all wrong.

I seams as the entry don't gets its content until you press enter.
The funny thing is that the signal "backspace" works as expected.

The signals work as described.

There should realy be a signal "key-insert" to validate characters
in progress into the entry widget. But I can't find sutch.

It should be mandatory to read at least the FAQ:
http://gtk.org/faq/#AEN843

Yeti

--
http://gwyddion.net/



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