我想創建一個簡單的程序,它從glade文件中提取一個GtkHButtonBox,向它添加一個按鈕並顯示整個窗口。問題是我看不到任何我添加的按鈕,並且我沒有看到任何警告錯誤或斷言。c gtk + -2:看不到添加到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和林間空地3.6.7
任何想法如何解決這個問題?
謝謝
不幸的是,在添加gtk_widget_show(button)後結果是一樣的。 – ufk 2011-03-06 09:53:00
我剪切並粘貼了上面的代碼,添加了#include,用我的本地文件名替換了UI_FILE,並且我看到一個帶有標籤爲「moshe」的按鈕的窗口。也許這個問題不是粘貼在這裏的代碼。 –
2011-03-06 19:44:21
嗯..怪異。我會檢查出來的。謝謝 – ufk 2011-03-06 20:54:10