我在codeblocks运行时遇到麻烦。它说“(HelloWorld.exe:3312):libglade-CRITICAL **:glade_xml_relative_file:断言 `filename!= NULL'失败“
我正在使用Glade和GTK为我的项目构建一个用户界面,但我已经工作了好几天,我仍然无法弄清楚出了什么问题? 谢谢。
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
/*import glade file*/
xml = glade_xml_new("hello.glade", NULL, NULL);
/* get a widget (useful if you want to change something) */
widget = glade_xml_get_widget(xml, "mainWindow");
/* connect signal handlers */
glade_xml_signal_autoconnect(xml);
/*show widget*/
gtk_widget_show (widget);
gtk_main();
return 0;
}
它构建良好,当我尝试运行它时它不会运行。
答案 0 :(得分:1)
林间空地文件基本上有两种格式:1:libglade
,2:gtkBuilder
。
我在夏季项目工作时也面临同样的问题。而不是使用glade_xml_new()
使用gtk_builder_new()
来构建您的glade文件,因为我认为您的glade文件是gtkBuilder
类型。
示例程序:
int main(int argc, char *argv[])
{
GtkBuilder *gtkBuilder;
GtkWidget *window;
gtk_init(&argc, &argv);
gtkBuilder = gtk_builder_new();
gtk_builder_add_from_file(gtkBuilder, "name of your glade file", NULL);/*this api is used to
build the glade file which is created by using glade(glade3) UI designer.*/
window = GTK_WIDGET( gtk_builder_get_object( gtkBuilder, "name of your window") );
gtk_builder_connect_signals( gtkBuilder, NULL ); /*connecting signals so that appropriate
handler can be called to handle the button clicked event*/
g_object_unref(G_OBJECT(gtkBuilder));
gtk_widget_show(window);
gtk_main(); /*it is basically a loop to make window appear. if we not write it then window
will appear but disappear after few seconds automatically.*/
return 0;
}
示例程序不完整只是了解构建glade文件的正确方法 完整的程序以及有关如何使用gtk库构建GUI的更多信息,您可以参考http://programming-simplified.blogspot.com