Re: Bus failure using focus events



Hi Peter,

I'm not sure I understand. When I refer to using activate and focus-out-event, I'm talking about in seperate builds of the product - I change the signal type to "activate" and recompile, for example. "activate" should never come into play when I'm using a "focus-out-event".

However, I noticed the different params and I'm not sure that I'm handling this properly (I don't believe I understand signals terribly well, to be honest with you). I had assumed that in none of the code I've implemented, do I have to worry about the signal params - those were handled by GTK. I just connect to the signal, and pass the signal-connect params. Are you saying that I somehow have to build a GdkEventFocus object and pass it to focus-out-event? I'm not sure that I'm actually generating the call with the GtkEntry or gpointer when I connect to "activate" now, so I'm not sure at what point this would be done.

Thanks,
Ian

On Thursday, October 2, 2003, at 11:46 AM, Peter Krueger wrote:

Hi Ian,
when you connect a callback function you have to make sure that the
functions parameter list is appropriate to the signal you connect it to.
You can't use the same callback function since they have a different
signature:

"activate" void user_function(
  GtkEntry *entry,
  gpointer user_data);

"focus-out-event" gboolean user_function(
  GtkWidget *widget,
  GdkEventFocus *event,
  gpointer user_data);

When GTK calls the "focus-out-event" it places three arguments for your
callback function on the stack, but your "activate"-function only removes
two of them. This means that when your function returns there is still
some parameter data on the stack where it shouldn't be. This causes your
application to crash.

Regards...Peter

I'm trying to generate some code that checks the input a user has
provided into a text entry field, and appends a trailing character if
needed.  I'd like to do it as soon as the user switches away from the
widget, and is presumably done editing.

If I use an "activate" signal, things work fine - it does exactly what
I expect, with no complaints.

However, if I use a "focus-out-event", the program eventually
terminates and I get, simply, a "Bus error" message.

This happens using GTK+1.2.10, 2.0.6, as well as 2.2.1.

Can anyone point me to what I'm doing wrong?

Here's some of the code:

Here's where I connect the signal and generate the widget:

#if GTK_MAJOR_VERSION < 2

#define SIGNAL_CONNECT(widget, name, callback, arg) \
gtk_signal_connect(GTK_OBJECT(widget), name, GTK_SIGNAL_FUNC(callback),
\
                    (gpointer)(arg))

#else /* GTK_MAJOR_VERSION >= 2 */

#define SIGNAL_CONNECT(widget, name, callback, arg) \
g_signal_connect(G_OBJECT(widget), name, G_CALLBACK(callback), \
                  (gpointer)(arg))

         fileopen_dir_te = create_preference_entry(main_tb, 9,
"Directory:", NULL, prefs.gui_fileopen_dir);
OBJECT_SET_DATA(main_vb, GUI_FILEOPEN_DIR_KEY, fileopen_dir_te);
         SIGNAL_CONNECT(fileopen_dir_te, "focus-out-event",
fileopen_dir_changed_cb, NULL);

Again, if I replace "focus-out-event" with "activate", things work fine
if I just hit enter in the text entry field.

static void
fileopen_dir_changed_cb(GtkWidget *fileopen_entry _U_, gpointer
parent_w)
{
     char *lastchar;
     gint fileopen_dir_te_length;

     fileopen_dir_te = (GtkWidget *)OBJECT_GET_DATA(parent_w,
GUI_FILEOPEN_DIR_KEY);
     fileopen_dir_te_length = strlen(gtk_entry_get_text
(GTK_ENTRY(fileopen_entry)));
     lastchar = gtk_editable_get_chars(GTK_EDITABLE(fileopen_entry),
fileopen_dir_te_length-1, -1);
     if (strcmp(lastchar, "/") != 0)
         gtk_entry_append_text(GTK_ENTRY(fileopen_entry), "/");
     return;
}

Is there a stupid mistake I made here?

Thanks,
Ian
--
====================================================================
Peter Krüger

applied software solutions (appss) GmbH
Sandtorstr. 23
D-39106 Magdeburg
Germany

Phone:  +49-(0)391-54486-19388
Fax:    +49-(0)391-54486-19222
email:  krueger appss de
URL:    http://www.appss.de

Managing Director: Uwe Hess, Dietmar Schäfer
Register: HRB12386, AG Mageburg

"Virtual business becomes reality!"

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
====================================================================

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





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