GTK-在关闭窗口时运行功能

问题描述 投票:0回答:1

当我在GTK窗口中单击“ 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'

这是我的职能:

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;
}

任何人都可以阐明我在做什么错吗?非常感谢

c callback window gtk
1个回答
1
投票

“删除事件”信号在GtkWidget个实例上可用,在GtkWidget个实例上不可用。

您需要将GtkApplication回调连接到要添加到应用程序中的GtkApplication上的test信号。

© www.soinside.com 2019 - 2024. All rights reserved.