我試圖創建一個使用GtkBuilder和格萊德一個真的簡單的GUI。爲了實現這一點,我遵循官方的Gtk + 3參考手冊的教程。原碼唯一的區別是,我不連接到widget的信號,簡單(因此除去過多的回調函數):GtkBuilder忽略的.ui文件
#include <gtk/gtk.h>
int
main (int argc,
char *argv[])
{
GtkBuilder *builder;
GObject *window;
GObject *button;
gtk_init (&argc, &argv);
/* Construct a GtkBuilder instance and load our UI description */
builder = gtk_builder_new();
gtk_builder_add_from_file (builder, "builder.ui", NULL);
gtk_main();
return 0;
}
在教程中使用的「builder.ui」文件的樣子這個:
<interface>
<object id="window" class="GtkWindow">
<property name="visible">True</property>
<property name="title">Grid</property>
<property name="border-width">10</property>
<child>
<object id="grid" class="GtkGrid">
<property name="visible">True</property>
<child>
<object id="button1" class="GtkButton">
<property name="visible">True</property>
<property name="label">Button 1</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object id="button2" class="GtkButton">
<property name="visible">True</property>
<property name="label">Button 2</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object id="quit" class="GtkButton">
<property name="visible">True</property>
<property name="label">Quit</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
<property name="width">2</property>
</packing>
</child>
</object>
<packing>
</packing>
</child>
</object>
</interface>
......並且根本沒有問題。該程序編譯並生成所需的窗口。但是,當我嘗試使用我自己的.ui文件(由glade 3.10.0生成)時,我根本沒有得到任何結果。應用程序進入主循環並且不出現窗口。我使用的GUI文件是:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="Window">
<property name="can_focus">False</property>
<property name="border_width">15</property>
<child>
<object class="GtkLabel" id="fooLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">foobar</property>
</object>
</child>
</object>
</interface>
我在做什麼錯?