J'essaie de connecter un signal GtkAction au callback open_file mais apparemment il me manque quelque chose car il ne se passe rien lorsque je sélectionne Ouvrir dans le menu fichier. Des indices?Comment connecter le signal GtkAction?
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>
Y at-il des messages d'erreur sur la console? – sarnold
Aucun message d'erreur et aucun message "open_file" non plus. –