Gtk-WARNING **:找不到信号处理程序

时间:2017-03-15 14:27:25

标签: gtk signals handler glade geany

我使用Glade创建了非常简单的GTK + GUI,其中包含一个切换按钮。我想为此按钮分配操作。我有一个问题,让按钮的信号处理程序工作。编译并运行后,我收到此消息:

  

Gtk-WARNING **:找不到信号处理程序   ' on_togglebutton1_toggled&#39 ;.你用-rdynamic编译了吗?

我当前的C代码如下所示:

#include <gtk/gtk.h>
#include <stdio.h> 
#include "f_back.h"

#define UI_FILE "gui.ui"

GtkWidget * create_window( void )
{
    GtkWidget * window;
    GtkBuilder * builder;
    GError * error = NULL;

    builder = gtk_builder_new();
    if( !gtk_builder_add_from_file( builder, UI_FILE, & error ) )
    {
        g_warning( "Can't load builder file: %s", error->message );
        g_error_free( error );
    }    

    gtk_builder_connect_signals( builder, NULL );

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

    g_object_unref( builder );

    return window;
}


int
main( int argc, char * argv[] )
{
    GtkWidget * window;

    gtk_init( & argc, & argv );

    okno = create_window();
    gtk_widget_show( window );
    gtk_main()

    return 0;
}

f_back.h:

#include <gtk/gtk.h>

void on_togglebutton1_toggled( GtkToggleButton * togglebutton, gpointer user_data );

f_back.c:

#include "f_back.h"

void on_togglebutton1_toggled( GtkToggleButton * togglebutton, gpointer user_data )
{
    g_print( "Toggle button pressed\n" );
}

GTK + UI:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
  <requires lib="gtk+" version="3.12"/>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes">Testowe</property>
    <property name="window_position">center</property>
    <signal name="destroy" handler="gtk_main_quit" swapped="no"/>
    <child>
      <object class="GtkGrid" id="grid1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="row_homogeneous">True</property>
        <property name="column_homogeneous">True</property>
        <child>
          <object class="GtkImage" id="image1">
            <property name="name">logo</property>
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="yalign">0.10000000149011612</property>
            <property name="pixbuf">logo_large.bmp</property>
            <style>
              <class name="logo"/>
            </style>
          </object>
          <packing>
            <property name="left_attach">0</property>
            <property name="top_attach">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkToggleButton" id="togglebutton1">
            <property name="label" translatable="yes">LED ON/OFF</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="receives_default">True</property>
            <signal name="toggled" handler="on_togglebutton1_toggled" swapped="no"/>
          </object>
          <packing>
            <property name="left_attach">0</property>
            <property name="top_attach">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
        <style>
          <class name="grid"/>
        </style>
      </object>
    </child>
  </object>
</interface>

我在论坛上尝试了很多选项:

  • 使用-rdynamic进行编译,
  • 使用-export-dynamic编译,
  • 使用-lgmodule-2.0编译,
  • 添加gmodule-export-2.0库。
  • 添加extern&#34; C&#34;在函数声明之前,
  • 使用G_MODULE_EXPORT。

这些解决方案都没有奏效。我总是得到同样的信息。

我目前的Geany构建命令:

  

g ++ -Wall -c&#34;%f&#34; -l wiringPi pkg-config --cflags gtk+-3.0 --libs gtk+-3.0 gmodule-export-2.0 -rdynamic -export-dynamic -lgmodule-2.0

     

g ++ -Wall -o&#34;%e&#34; &#34;%F&#34; -l wiringPi pkg-config --cflags gtk+-3.0 --libs gtk+-3.0 gmodule-export-2.0 -rdynamic -export-dynamic -lgmodule-2.0

有人知道我的代码有什么问题吗?

1 个答案:

答案 0 :(得分:0)

尝试将行okno = create_window();更改为window = create_window();