exiting app doesn't seem to work as documented



Hi all,

trying to build this gtk2 GUI with glade, but it won't quit
properly.

If I make the delete event return FALSE, it still doesn't seem
to trigger the destroy event (correctly) and seems to loop in
g_main_context_dispatch. I always need to CTRL-C, though the
window dissappears.
(find gdb session below)
What completely beats me is that I get the HelloWorld example
from the docs to do it.

If I explicitly call on_window1_destroy_event from my delete
callback (prior to the return, of course) and have gtk_main_quit()
and exit() in the destroy callback things kinda work but it seems
awkward and like it should work differently.
(Also, if I leave away the exit(0) and want to return to main(),
I get a segfault.)


All hints or rtfms welcome,
TIA,

Karl.


Here are my callbacks:

gboolean
on_window1_delete_event                (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
g_print("delete event occurred!\n");
//      gtk_signal_emit_by_name((GtkObject*) widget, "destroy_event");
        return FALSE;
}
gboolean
on_window1_destroy_event               (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
g_print("destroy event occurred!\n");
        gtk_main_quit ();
//  return FALSE;
}

set up like this:

  g_signal_connect ((gpointer) window1, "delete_event",
                    G_CALLBACK (on_window1_delete_event),
                    NULL);
  g_signal_connect ((gpointer) window1, "destroy_event",
                    G_CALLBACK (on_window1_destroy_event),
                    NULL);

and main.c:

int
main (int argc, char *argv[])
{
  GtkWidget *window1;
  GtkWidget *dialog1;
#ifdef ENABLE_NLS
  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif
gtk_set_locale ();
  gtk_init (&argc, &argv);
add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); /*
   * The following code was added by Glade to create one of each component
   * (except popup menus), just so that you see something after building
   * the project. Delete any components that you don't want shown initially.
   */
  window1 = create_window1 ();
  gtk_widget_show (window1);
//  dialog1 = create_dialog1 ();
//  gtk_widget_show (dialog1);
gtk_main ();
  exit (0);
  return 0;
}


gdb session:

kb87850 ono-sendai(570)> gdb project2
GNU gdb 2002-04-01-cvs
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-linux"...
(gdb) break on_window1_delete_event
Breakpoint 1 at 0x804d67b: file callbacks.c, line 20.
(gdb) break on_window1_destroy_event
Breakpoint 2 at 0x804d693: file callbacks.c, line 31.
(gdb) run
Starting program: /export/home/kb87850/Projekte/project2/src/project2
delete event occurred!
Breakpoint 1, on_window1_delete_event (widget=0x8084318, event=0x80e81a8, user_data=0x0) at callbacks.c:20
20              return FALSE;
(gdb) s
0x400da412 in _gtk_marshal_BOOLEAN__BOXED () from /usr/lib/libgtk-x11-2.0.so.0
(gdb) s
Single stepping until exit from function _gtk_marshal_BOOLEAN__BOXED,
which has no line number information.
0x40346e2b in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
(gdb) s
Single stepping until exit from function g_closure_invoke,
which has no line number information.
0x40359f23 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
(gdb) s
Single stepping until exit from function g_signal_emit_by_name,
which has no line number information.
0x40358807 in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
(gdb) s
Single stepping until exit from function g_signal_emit_valist,
which has no line number information.
0x403671d0 in g_value_transforms_init () from /usr/lib/libgobject-2.0.so.0
(gdb) s
Single stepping until exit from function g_value_transforms_init,
which has no line number information.
0x4035895e in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
(gdb) s
Single stepping until exit from function g_signal_emit_valist,
which has no line number information.
0x40358a45 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
(gdb) s
Single stepping until exit from function g_signal_emit,
which has no line number information.
0x40195f02 in gtk_widget_send_expose () from /usr/lib/libgtk-x11-2.0.so.0
(gdb) s
Single stepping until exit from function gtk_widget_send_expose,
which has no line number information.
0x40195b60 in gtk_widget_event () from /usr/lib/libgtk-x11-2.0.so.0
(gdb) s
Single stepping until exit from function gtk_widget_event,
which has no line number information.
0x400d91ed in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
(gdb) s
Single stepping until exit from function gtk_main_do_event,
which has no line number information.
0x4026c6ad in _gdk_events_queue () from /usr/lib/libgdk-x11-2.0.so.0
(gdb) s
Single stepping until exit from function _gdk_events_queue,
which has no line number information.
0x4039bf59 in g_get_current_time () from /usr/lib/libglib-2.0.so.0
(gdb) s
Single stepping until exit from function g_get_current_time,
which has no line number information.
0x4039cd77 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
(gdb) s
Single stepping until exit from function g_main_context_dispatch,
which has no line number information.
Program received signal SIGINT, Interrupt.
0x404a9bb0 in poll () from /lib/libc.so.6
(gdb) q




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