Re: auto connect signals

Xiao Yafeng <[email protected]>
Newsgroups gmane.comp.gnome.glade.devel
Message-ID <[email protected]>
Thanks for reply!
I modify the code as suggested and rerun:
hello.c:
#include <gtk/gtk.h>

void on_button_quit_clicked (GtkWidget *button, gpointer userdata){
    gtk_main_quit();
}

int main (int argc, char **argv){
    GtkBuilder *builder;
    GtkWidget *window;
    GtkWidget *button;
    gtk_init (&argc, &argv);
    builder = gtk_builder_new();
     window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
    gtk_builder_add_from_file(builder, "hello.glade", NULL);
    gtk_builder_connect_signals(builder, NULL);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

hello.glade:
<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.16"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="window1">
    <child>
      <object class="GtkVPaned" id="vpaned1">
        <property name="visible">True</property>
        <property name="can_focus">True</property>
        <property name="orientation">vertical</property>
        <child>
          <object class="GtkLabel" id="label1">
            <property name="visible">True</property>
            <property name="label" translatable="yes">label</property>
          </object>
          <packing>
            <property name="resize">False</property>
            <property name="shrink">True</property>
          </packing>
        </child>
        <child>
          <object class="GtkHBox" id="hbox1">
            <property name="visible">True</property>
            <child>
              <placeholder/>
            </child>
            <child>
              <object class="GtkHButtonBox" id="hbuttonbox1">
                <property name="visible">True</property>
                <child>
                  <object class="GtkButton" id="button_quit">
                    <property name="label"
translatable="yes">quit</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <signal name="clicked"
handler="on_button_quit_clicked"/>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkButton" id="button2">
                    <property name="label"
translatable="yes">button</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">1</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <placeholder/>
            </child>
          </object>
          <packing>
            <property name="resize">True</property>
            <property name="shrink">True</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>


error messages:
                (hello:12512): Gtk-WARNING **: Could not find signal handler
'on_button_quit_clicked'
Segmentation fault


new error message confuse me. It seems I do not pass the callback function
to button widget successfully.  I 've tried to connect signals explicit:
first, ERASE signal handler in hello.glade.
hello.c
          #include <gtk/gtk.h>

void on_button_quit_clicked (GtkWidget *button, gpointer userdata){
    gtk_main_quit();
}

int main (int argc, char **argv){
    GtkBuilder *builder;
    GtkWidget *window;
    GtkWidget *button;
    gtk_init (&argc, &argv);
    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, "hello.glade", NULL);
    window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));

    button = GTK_WIDGET(gtk_builder_get_object(builder,"button_quit"));
    g_signal_connect( G_OBJECT(button), "clicked",
            G_CALLBACK(on_button_quit_clicked), NULL);
    gtk_builder_connect_signals(builder, NULL);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

Above code could be run correctly, but writing many g_signal_connect is very
tedious.
Is there a way to auto connect callback function to widget designed by glade
or I miss something?









On Thu, Aug 6, 2009 at 12:18 PM, Tristan Van Berkom <
[email protected]> wrote:

> On Wed, Aug 5, 2009 at 11:37 PM, Xiao Yafeng<[email protected]> wrote:
> > I'm new to glade programming. below is my first gtk+ snippet with glade.
> > hello.c:
> [...]
> > error message:
> >
> > (hello:8403): Gtk-WARNING **: Could not lookup object NULL on signal
> clicked
> > of object button_quit
> >
> > (hello:8403): Gtk-CRITICAL **: gtk_main_quit: assertion `main_loops !=
> NULL'
> > failed
> > Segmentation fault
> >
> >
> > It seems NULL is cause of failure, but who can post a correct code to
> prove
> > my guess?
> >
>
> The "object" parameter is a string to be set by the user in Glade - I have
> no
> idea how you ended up with the string NULL, it should just be empty if you
> dont want to specify an object.
>
> Note also when using the "object" (userdata) field, the specified object
> will
> be swapped with the emitting object and thus come first in the callback`s
> argument list (the string specified for "object" is a name of another
> object
> in the same Glade file).
>
> Cheers,
>           -Tristan
>

_______________________________________________
Glade-devel maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/glade-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.