Re: gtk_entry and "changed" signal in gtk+-2.0



Oliver Rauch <oliver rauch rauch-domain de> writes:

Owen Taylor wrote:

It's still an "official" signal, on the GtkEditable interface:

 http://developer.gnome.org/doc/API/2.0/gtk/gtk-gtkeditable.html

Is it also still an official signal of the GtkEntry interface?

Since, GtkEntry implements the GtkEditable interface, yes, it has
this signal.

 http://bugzilla.gnome.org/show_bug.cgi?id=64998

Ok. I see.

[ What if the user deleted the text and typed something else in? I don't think
  it should be a huge problem for most apps if the contents of an entry are
  temporarily in an empty state. ]

This is a problem when you do the following:

static gchar *text;

entry_changed_callback(GtkEntry *entry, void *data)
{
  if (text)
    free(text)

  text = strdup(gtk_entry_get_text(entry));
}


main()
{
...
text=strdup("Hello"); /* this is the global defined *text */
gtk_entry_set_text(entry, text);
...
}


The problem is that the first callback frees the memory in which
the text "Hello" is stored, in the second callback the text
is not available any more.

Certainly, the idea is to fix the double ::changed signal on the
principle of least surprise;  the general rule, however, is that you must
make sure that any parameters passed to a function live until the end
of the function.

                                        Owen



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