1
votes

I am a green hand in GTK. I came across such problem when I used Glade Interface Designer to design a UI. My purpose is to design two window.And one of button in main_window controls the appearance of create_log_in_window. I had add function 'create_log_in_window' and Object 'main_window' in Glade. However, the button is invalid when I run the program. And such warning was appearing. Here are the codes and warnings:

Gtk-WARNING:Could not find signal handler in 'create_log_in_window'

#include <gtk/gtk.h>
int main (int argc, char *argv[]){

    GtkBuilder      *builder;
    GtkWidget       *main_window;

    gtk_init (&argc, &argv);

    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder,"main_window.glade", NULL);
    main_window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
    gtk_builder_connect_signals(builder, NULL);
    g_object_unref(G_OBJECT(builder));

    gtk_widget_show_all(main_window);
    gtk_main();

    return 0;
}

gboolean create_log_in_window(GtkWidget *main_window){

    GtkBuilder *builder;
    GtkWidget  *window;

    gtk_widget_hide_all(main_window);

    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder,"log_in_window.glade",NULL);
    window = GTK_WIDGET(gtk_builder_get_object(builder,"log_in_window"));
    gtk_builder_connect_signals(builder,NULL);
    g_object_unref(G_OBJECT(builder));

    gtk_widget_show_all(window);
    return true;
}
1
If i recall correctly, the c++ builder doesn't support signals defined in glade. You will have to write them manually in c++. This defect seems to be comfirmed by stackoverflow.com/questions/4089077/…Captain Giraffe
what signal of which widget did you try to connect create_log_in_window() to? Have you checked that your function signature is correct for that signal?Jussi Kukkonen
I used a 'clicked' signal in a button to connect create_log_in_window().@jku张长庚
Thank you for you help anyway. But it works when I connect a button to gtk_main_quit() function. I'll try to write signals manually then to check. @CaptainGiraffe张长庚

1 Answers

1
votes

I referred to a lot of information and finally found something useful in this website: http://blog.csdn.net/xuesen_lin/article/details/6001114 The key is we should define our function in a special way in order to let the plate find the function address. Maybe my description is unclear. So I'll show my code.

#include <gtk/gtk.h>

typedef struct _MainDate{

    GtkWidget *main_window;
    GtkWidget *delete_button;

}MainDate;


G_MODULE_EXPORT void delete_confirm_window( GtkButton *button, GtkWidget *popup ){

    GtkBuilder *builder;
    GtkWidget  *delete_window;
    GError *error = NULL;

    builder = gtk_builder_new();
    if(!(gtk_builder_add_from_file(builder,"delete_window.glade",&error))){
        g_warning("%s",error->message);
        g_free(error);
        return ;
    }

    delete_window = GTK_WIDGET(gtk_builder_get_object(builder,"delete_confirm_window"));
    gtk_builder_connect_signals(builder,NULL);

    g_object_unref(builder);

    gtk_widget_show(delete_window);

}

int main(int argc,char *argv[]){

    GtkBuilder *builder;
    MainDate *date;
    GError  *error = NULL;

    gtk_init(&argc,&argv);

    builder = gtk_builder_new();
    if(!(gtk_builder_add_from_file(builder,"main_window.glade",&error))){
        g_warning("%s",error->message);
        g_free(error);
        return 1;
    }

    date = g_slice_new(MainDate);

    date->main_window =      GTK_WIDGET(gtk_builder_get_object(builder,"main_window"));
    date->delete_button = GTK_WIDGET(gtk_builder_get_object(builder,"delete_popmenu"));

    gtk_builder_connect_signals(builder,date);

    g_object_unref(builder);

    gtk_widget_show_all(date->main_window);

    gtk_main();

    g_slice_free(MainDate,date);

    return 0;

}