代码之家  ›  专栏  ›  技术社区  ›  kaidentity

GTK+3.0与Glade 3.10:未找到信号处理器,菜单未显示

  •  0
  • kaidentity  · 技术社区  · 10 年前

    我用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;
    }
    

    glade文件:

    <?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 回复  |  直到 10 年前
        1
  •  1
  •   Community Jaime Torres    7 年前

    修复了它。问题是:

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