I am a newbie in GTK+ and I do not understand what’s wrong with my callback function. Could you help me please?
I want to change my box orientation, but somehow my box pointer is wrong inside my callback function.
My code:
#include <gtk/gtk.h>
#include <stdio.h>
void flip_buttons(GtkWidget *window, gpointer user_data) {
gtk_orientable_set_orientation(
(GtkOrientation *)user_data,
GTK_ORIENTATION_VERTICAL);
}
int main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *box;
GtkWidget *button;
GtkWidget *button2;
gtk_init (&argc,&argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
button = gtk_button_new_with_label ("Btn A");
button2 = gtk_button_new_with_label ("Btn B");
gtk_container_add (GTK_CONTAINER(window), box);
gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), button2, TRUE, TRUE, 0);
gtk_widget_show_all (window);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
GClosure* closure_flip_buttons =
g_cclosure_new(G_CALLBACK(flip_buttons), box, 0);
// Set up the accelerator group.
GtkAccelGroup* accel_group = gtk_accel_group_new();
gtk_accel_group_connect(accel_group,
GDK_KEY_F,
GDK_CONTROL_MASK,
0,
closure_flip_buttons);
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
gtk_main();
return 0;
}
The above code compiles, but then I have this error:
Gtk-CRITICAL **: 10:51:36.721: gtk_orientable_set_orientation: assertion 'GTK_IS_ORIENTABLE (orientable)' failed