Reputation: 334
I'm trying to run a simple function when the 'x' button is clicked in my GTK window but am having trouble getting this to work. I get this error every time I run it:
(process:17950): GLib-GObject-WARNING **: 11:58:51.480: ../../../../gobject/gsignal.c:2523: signal 'delete-event' is invalid for instance '0x55a183d991a0' of type 'GtkApplication'
Here are my functions:
main():
int main(int argc, char **argv) {
GtkApplication *app;
int status;
// Set up the application and start it
app = gtk_application_new ("com.sds.hashcrack.server", G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK (init), NULL);
g_signal_connect (app, "delete-event", G_CALLBACK (test), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
test():
gboolean test(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
g_print("Closed");
return true;
}
Can anyone shed any light on what I'm doing wrong? Many thanks
Upvotes: 1
Views: 587
Reputation: 8805
The "delete-event" signal is available on GtkWidget
instances, not on GtkApplication
ones.
You will need to connect the test
callback to the delete-event
signal on the GtkWindow
you're adding to your application.
Upvotes: 2