带Glade 3.10的GTK + 3.0:未找到信号处理程序,菜单未显示

时间:2014-09-02 11:15:05

标签: gtk gtk3 glade

我用Glade 3.16.1和GTK + 3.0(版本3.10.8)编写了一个非常简单的程序,但几乎没有任何作用。

找不到信号处理程序gtk_main_quit,并且不显示菜单。

我用

构建程序
gcc gtktest.c -o gtktest -Wall $(pkg-config --cflags --libs gtk+-3.0 gmodule-2.0)

源代码(gtktest.c):

#include <gtk/gtk.h>
#include <string.h>

void kleine_callback (GtkWidget *w, gpointer d)
{
    GtkWidget *dialog;
    dialog = gtk_message_dialog_new (NULL,
    GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hallo, Welt!");
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy (dialog);
}

void quit (GtkWidget * w, gpointer d)
{
    gtk_main_quit ();
}

int main (int argc, char *argv[])
{
    GtkBuilder *builder;
    GError *error = NULL;
    GtkWidget *window;
    gtk_init (&argc, &argv);
    builder = gtk_builder_new ();
    if (!gtk_builder_add_from_file (builder, "kaixN.glade", &error)) {        
        g_warning ("%s", error->message);
        g_free (error);
        return 1;
    }
    gtk_builder_connect_signals (builder, NULL);
    window = GTK_WIDGET(gtk_builder_get_object (builder,  "main_window"));
    gtk_widget_show_all (window);
    gtk_main ();
    return 0;
}

林间文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkWindow" id="main_window">
    <property name="width_request">600</property>
    <property name="height_request">400</property>
    <property name="can_focus">False</property>
    <property name="resizable">False</property>
    <child>
      <object class="GtkBox" id="main_vbox">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkMenuBar" id="main_menu">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkMenuItem" id="menuitem1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">_Datei</property>
                <property name="use_underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu" id="menu1">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <child>
                      <object class="GtkImageMenuItem" id="menu_item_add">
                        <property name="label">gtk-add</property>
                        <property name="related_action"/>
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
            <child>
              <object class="GtkMenuItem" id="menu_help">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">_Hilfe</property>
                <property name="use_underline">True</property>
                <child type="submenu">
                  <object class="GtkMenu" id="menu3">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <child>
                      <object class="GtkImageMenuItem" id="menu_item_quit">
                        <property name="label">gtk-quit</property>
                        <property name="use_action_appearance">True</property>
                        <property name="related_action"/>
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <property name="use_underline">True</property>
                        <property name="use_stock">True</property>
                        <signal name="select" handler="quit" swapped="no"/>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkStatusbar" id="status_bar">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="margin_left">10</property>
            <property name="margin_right">10</property>
            <property name="margin_top">6</property>
            <property name="margin_bottom">6</property>
            <property name="orientation">vertical</property>
            <property name="spacing">2</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="pack_type">end</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

一切都那么简单,我看不出我做错了什么...... 谢谢 启

1 个答案:

答案 0 :(得分:1)

修正了它。问题是:

1:信号没有正确连接到事件。 2:菜单在那里,但我只是看错了地方。我在Unity中使用Ubuntu,因此菜单显示在显示器的顶部,而不是显示在应用程序窗口的顶部。这篇文章引起了我的注意:https://askubuntu.com/questions/460819/ubuntu-gtk-3-10-8-not-able-to-visualize-a-menubar-made-by-glade