我正在尝试创建一个简单的程序,该程序从 gade 文件中获取 GtkHButtonBox,向其中添加一个按钮并显示整个窗口。问题是我看不到我添加的任何按钮,也没有看到任何警告错误或断言。
这是我的 main.c 文件:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <gtk/gtk.h>
GtkBuilder *builder;
#define UI_FILE "gtk_hbuttonbox.ui"
int
main (int argc, char *argv[])
{
GtkWidget *window,*box, *button;
gtk_set_locale ();
gtk_init (&argc, &argv);
GError* error = NULL;
builder = gtk_builder_new ();
if (!gtk_builder_add_from_file (builder, UI_FILE, &error))
{
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
}
/* This is important */
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
box = GTK_WIDGET (gtk_builder_get_object (builder, "hbuttonbox1"));
g_object_unref (builder);
button = GTK_WIDGET(gtk_button_new_with_label ("moshe"));
gtk_box_pack_start (GTK_BOX(box),button,FALSE,FALSE,0);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
这是我的 gtk_hbuttonbox.ui 林间空地文件:
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window">
<property name="visible">True</property>
<property name="title" translatable="yes">window</property>
<property name="default_width">500</property>
<property name="default_height">400</property>
<signal name="destroy" handler="destroy" object="NULL"/>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</interface>
使用 gtk+ 2.22.1 和 glade 3.6.7
任何想法如何解决这个问题?
谢谢