auto connect signals

View: New views
5 Messages — Rating Filter:   Alert me  

auto connect signals

by Xiao Yafeng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm new to glade programming. below is my first gtk+ snippet with glade.
hello.c:

#include <gtk/gtk.h>

static int count;
void on_button_quit_clicked (GtkWidget *button, gpointer userdata){
    //gtk_window_resize(window,(gint)100+count,(gint)100+count);
    //count = count + 1;
    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);
    gtk_builder_connect_signals(builder,(GtkBuilde,NULL);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

hello.glade:

<?xml version="2.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="NULL"/>
                  </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 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?

TIA

_______________________________________________
Glade-devel maillist  -  Glade-devel@...
http://lists.ximian.com/mailman/listinfo/glade-devel

Re: auto connect signals

by Tristan Van Berkom-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Aug 5, 2009 at 11:37 PM, Xiao Yafeng<xyf.xiao@...> 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  -  Glade-devel@...
http://lists.ximian.com/mailman/listinfo/glade-devel

Re: auto connect signals

by Xiao Yafeng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 <tristan.van.berkom@...> wrote:
On Wed, Aug 5, 2009 at 11:37 PM, Xiao Yafeng<xyf.xiao@...> 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  -  Glade-devel@...
http://lists.ximian.com/mailman/listinfo/glade-devel

Re: auto connect signals

by Alexey Kurochkin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, 2009-08-06 at 13:59 +0800, Xiao Yafeng wrote:
> error messages:
>                 (hello:12512): Gtk-WARNING **: Could not find signal
> handler 'on_button_quit_clicked'

> Is there a way to auto connect callback function to widget designed by
> glade or I miss something?
>

Seems like you're missing -export-dynamic flag to gcc. You may want to
read through some glade tutorial. Here's one:
http://www.micahcarrick.com/12-24-2007/gtk-glade-tutorial-part-1.html


_______________________________________________
Glade-devel maillist  -  Glade-devel@...
http://lists.ximian.com/mailman/listinfo/glade-devel

Re: auto connect signals

by Xiao Yafeng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I modified Makefile to pkg-config --cflags --libs gtk+-2.0 gmodule_export-2.0
It's Okay! Thanks.

On Thu, Aug 6, 2009 at 9:15 PM, Alexey Kurochkin <alexey.kurochkin@...> wrote:
On Thu, 2009-08-06 at 13:59 +0800, Xiao Yafeng wrote:
> error messages:
>                 (hello:12512): Gtk-WARNING **: Could not find signal
> handler 'on_button_quit_clicked'

> Is there a way to auto connect callback function to widget designed by
> glade or I miss something?
>

Seems like you're missing -export-dynamic flag to gcc. You may want to
read through some glade tutorial. Here's one:
http://www.micahcarrick.com/12-24-2007/gtk-glade-tutorial-part-1.html


_______________________________________________
Glade-devel maillist  -  Glade-devel@...
http://lists.ximian.com/mailman/listinfo/glade-devel


_______________________________________________
Glade-devel maillist  -  Glade-devel@...
http://lists.ximian.com/mailman/listinfo/glade-devel