我使用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>
我在论坛上尝试了很多选项:
这些解决方案都没有奏效。我总是得到同样的信息。
我目前的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.0g ++ -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
有人知道我的代码有什么问题吗?
答案 0 :(得分:0)
尝试将行okno = create_window();
更改为window = create_window();