The "on destroy" signal handler function has to be connected to the top level window
inside the gtk loop in main() (that is, after the window is defined but before
gtk_main();), otherwise those functions are not actually called by anything. I don't use windows so I'm not sure if it's the same, but at least with linux/X you have to account for two possible termination signals from the window manager -- the normal "close" which is a
delete_event and also the potential
destroy:
Code:
g_signal_connect (G_OBJECT (window1), "delete_event", G_CALLBACK (on_window1_destroy_event), NULL);
g_signal_connect (G_OBJECT (window1), "destroy", G_CALLBACK (on_window1_destroy_event), NULL);
You definitely want to use your second version of the function, with
gtk_main_quit() and not the one with exit(). You can make it a void rather than a gboolean as well (and take out "return FALSE"). That setup is for when you have two seperate callbacks, one for delete and one for destroy, wherein the delete function calls the destroy function expecting a FALSE -- but it seems unnecessary unless you have some more complicated reason for using two seperate functions, so you can just use the one:
Code:
void on_window1_destroy_event() {
gtk_main_quit();
}
In fact, when I write small experiments like this that don't require any further clean-up at the end, I just use:
Code:
g_signal_connect (G_OBJECT (window1), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (G_OBJECT (window1), "destroy", G_CALLBACK (gtk_main_quit), NULL);
Which is what you might as well do. There is a great
gtk+ forum, b/t/w.
ps. I think using glade will only make writing and comprehending your own programs more difficult in the long run.