Unable to connect signal and signal handler in Glade GTK+3

拈花ヽ惹草 提交于 2020-01-02 05:40:08

问题


Hi i'm working on a project in GTK+ 3 on Ubuntu 14.04 LTS. I'm trying to use Glade,but when i tried to connect a "toggled" signal of toggle button to a function called kaczka ,after compiling i got this in my console: (Gra_w_Statki:11072): Gtk-Warning**:Could not find signal handler 'kaczka. Did you compile with -rdynamic?

The window and the button render itself and work normally except of that toggling button doesn't change anything. What am i doing wrong ?

This is how i tried to connect toggle button and function Click!

My Linker Settings are : pkg-config --libs gtk+-3.0

And my compiler settings are: pkg-config --cflags gtk+-3.0

I'm using Code ::Blocks 13.12 with GCC compiler.

And this is my code:

#include <stdlib.h>
#include <gtk/gtk.h>
void kaczka (GtkToggleButton *tbutton, gpointer data)
{
    gtk_main_quit ();
}


int main (int argc, char *argv[])
{
  GtkWidget *win = NULL;
  GtkBuilder *builder;

  gtk_init (&argc, &argv);


builder=gtk_builder_new();
gtk_builder_add_from_file( builder, "kaczka.glade", NULL);

    win=GTK_WIDGET(gtk_builder_get_object(builder,"window1"));


gtk_builder_connect_signals( builder, NULL );
g_object_unref( G_OBJECT( builder ) );



  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}

回答1:


Take a look at the gtk_builder_connect_signals() and gtk_builder_add_callback_symbol() documentation. Basically you need to either

  • use gtk_builder_add_callback_symbol() on all callbacks before connecting the signals or
  • link with gmodule-export-2.0 and use compile flags "-Wl,--export-dynamic" to export even unused symbols.



回答2:


You can add more compiler settings with,

pkg-config --libs --cflags gmodule-2.0.

If anyone is building the program with meson, just add

gmoddep = dependency('gmodule-2.0')

to list of dependencies.




回答3:


Add -rdynamic to export the function and make it visible to the loader.

> gcc pkg-config --cflags gtk+-3.0 -o kaczka kaczka.c pkg-config --libs gtk+-3.0

> ./kaczka

(kaczka:31686): Gtk-WARNING **: Could not find signal handler 'on_destroy'. Did you compile with -rdynamic?

> gcc pkg-config --cflags gtk+-3.0 -o kaczka kaczka.c pkg-config --libs gtk+-3.0 -rdynamic

> ./kaczka

No warning.




回答4:


I think your kaczka.glade maybe makes wrong.

I used your .c source file and created my own .glade, and it ran well.

What version of Glade are you trying?

Run the latest version and see if it solves the problem.



来源:https://stackoverflow.com/questions/27930691/unable-to-connect-signal-and-signal-handler-in-glade-gtk3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!