- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 Glade 创建了非常简单的 GTK+ GUI,其中包括一个切换按钮。我想为这个按钮分配 Action 。我在让按钮的信号处理程序工作时遇到问题。编译并运行后,我收到此消息:
Gtk-WARNING **: Could not find signal handler 'on_togglebutton1_toggled'. Did you compile with -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+ 用户界面:
<?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 "%f" -l wiringPi
pkg-config --cflags gtk+-3.0 --libs
-rdynamic -export-dynamic -lgmodule-2.0
gtk+-3.0 gmodule-export-2.0g++ -Wall -o "%e" "%f" -l wiringPi
pkg-config --cflags gtk+-3.0
-rdynamic -export-dynamic -lgmodule-2.0
--libs gtk+-3.0 gmodule-export-2.0
有人知道我的代码有什么问题吗?
最佳答案
尝试将 okno = create_window();
行更改为 window = create_window();
关于Gtk 警告 ** : Could not find signal handler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42812604/
我是一名优秀的程序员,十分优秀!