GTK - 运行 函数在 window 关闭
GTK - Run function on window close
当我的 GTK window 中单击 'x' 按钮时,我正在尝试 运行 一个简单的函数,但我无法让它工作。我每次 运行 都会收到此错误:
(process:17950): GLib-GObject-WARNING **: 11:58:51.480: ../../../../gobject/gsignal.c:2523: signal 'delete-event' is invalid for instance '0x55a183d991a0' of type 'GtkApplication'
这是我的功能:
主要():
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;
}
测试():
gboolean test(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
g_print("Closed");
return true;
}
任何人都可以阐明我做错了什么吗?非常感谢
"delete-event" 信号在 GtkWidget
instances, not on GtkApplication
个上可用。
您需要将 test
回调连接到要添加到应用程序的 GtkWindow
上的 delete-event
信号。
当我的 GTK window 中单击 'x' 按钮时,我正在尝试 运行 一个简单的函数,但我无法让它工作。我每次 运行 都会收到此错误:
(process:17950): GLib-GObject-WARNING **: 11:58:51.480: ../../../../gobject/gsignal.c:2523: signal 'delete-event' is invalid for instance '0x55a183d991a0' of type 'GtkApplication'
这是我的功能:
主要():
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;
}
测试():
gboolean test(GtkWidget *widget, GdkEvent *event, gpointer user_data) {
g_print("Closed");
return true;
}
任何人都可以阐明我做错了什么吗?非常感谢
"delete-event" 信号在 GtkWidget
instances, not on GtkApplication
个上可用。
您需要将 test
回调连接到要添加到应用程序的 GtkWindow
上的 delete-event
信号。