gtk glade aide:消灭信号问题

时间:2018-04-03 12:08:46

标签: gtk gtk3 glade

生成我刚刚打开信号的简单glade后,我想将它与我的.c连接,以便应用destroy信号,但总是得到异常

  

"我们找不到信号处理程序" on_window_main_destroy"

任何人都可以找出问题所在吗?

这是我在c

中的代码
#include <gtk/gtk.h>
GtkWidget *g_lbl_hello;
GtkWidget *g_lbl_count;

int main(int argc, char *argv[])
{
    GtkBuilder      *builder;
    GtkWidget       *window;

    gtk_init(&argc, &argv);

    builder = gtk_builder_new();
    gtk_builder_add_from_file (builder, "windows_main.glade", NULL);

    window = GTK_WIDGET(gtk_builder_get_object(builder, "windows_main"));

    // get pointers to the two labels
    g_lbl_hello = GTK_WIDGET(gtk_builder_get_object(builder, "lbl_hello"));
    g_lbl_count = GTK_WIDGET(gtk_builder_get_object(builder, "lbl_count"));
    gtk_builder_connect_signals(builder, NULL);
    //g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), G_OBJECT(window));

    g_object_unref(G_OBJECT(builder));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

// called when button is clicked

void on_btn_hello_clicked()
{
    static unsigned int count = 0;
    char str_count[30] = {0};

    gtk_label_set_text(GTK_LABEL(g_lbl_hello), "Hello, world!");
    count++;
    sprintf(str_count, "%d", count);
    gtk_label_set_text(GTK_LABEL(g_lbl_count), str_count);
}

// called when window is closed
void on_window_main_destroy()
{
    gtk_main_quit();
}

这是我的林间空地

enter image description here

1 个答案:

答案 0 :(得分:0)

您似乎正在使用MS Windows。如果是这种情况,那么gtk_builder_connect_signals的文档清楚地说:

  

在为Windows编译应用程序时,必须声明信号   使用G_MODULE_EXPORT进行回调,否则它们不会被放入符号中   表

使用G_MODULE_EXPORT

为您的回调模块添加前缀
G_MODULE_EXPORT void on_btn_hello_clicked()
{
...
}

G_MODULE_EXPORT void on_window_main_destroy()
{
...
}

PS:您可能需要将gmodule-2.0添加到依赖项。