我试图将GtkAction信号连接到回调open_file但显然我遗漏了一些东西,因为当我在文件菜单中选择Open时没有任何反应。有线索吗?
test.c的
#include <gtk/gtk.h>
void open_file(GtkAction *action, gpointer user_data)
{
g_print("open_file\n");
}
int main(int argc, char *argv[])
{
GtkBuilder *builder;
GObject *window;
gtk_init(&argc, &argv);
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "test.ui", NULL);
window = gtk_builder_get_object(builder, "window");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
test.ui
<interface>
<object class="GtkUIManager" id="uiman">
<child>
<object class="GtkActionGroup" id="actiongroup">
<child>
<object class="GtkAction" id="file">
<property name="label">_File</property>
</object>
</child>
<child>
<object class="GtkAction" id="open">
<property name="stock_id">gtk-open</property>
<signal name="activate" handler="open_file"/>
</object>
</child>
</object>
</child>
<ui>
<menubar name="menu_bar">
<menu action="file">
<menuitem action="open"/>
</menu>
</menubar>
</ui>
</object>
<object id="window" class="GtkWindow">
<property name="title">Test</property>
<child>
<object class="GtkVBox" id="vbox">
<child>
<object class="GtkMenuBar" id="menu_bar" constructor="uiman"/>
<packing>
<property name="expand">FALSE</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
答案 0 :(得分:2)
除非您致电gtk_builder_connect_signals()
。
答案 1 :(得分:1)
如果您打算将程序移植到Windows,您可能还需要在函数原型/定义中使用G_MODULE_EXPORT:
G_MODULE_EXPORT void my_callback(void); /* For example */