我是GTK的绿手。当我使用Glade Interface Designer设计UI时,我遇到了这样的问题。 我的目的是设计两个窗口.main_window中的一个按钮控制create_log_in_window的外观。 我在Glade中添加了'create_log_in_window'和Object'main_window'功能。 但是,当我运行程序时,该按钮无效。这样的警告正在出现。 以下是代码和警告:
Gtk-WARNING:在'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;
}
答案 0 :(得分:0)
我提到了很多信息,最后在这个网站上发现了一些有用的东西:http://blog.csdn.net/xuesen_lin/article/details/6001114 关键是我们应该以特殊的方式定义我们的函数,以便让板块找到函数地址。 也许我的描述不清楚。所以我会展示我的代码。
#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;
}