GNOME Bugzilla – Bug 316771
GtkSpinButton - emits "value_changed" twice sometimes
Last modified: 2018-05-02 14:14:21 UTC
If you set the step increment of a spin button with more precision than the number of digits shown, it emits "value_changed" twice for each click on the up/down arrows. (It seems to round the value first, then add the increment.) Here's a test app: /* * Compile with: * * gcc `pkg-config --cflags --libs gtk+-2.0` test-gtk.c */ #include <gtk/gtk.h> void on_spinbutton1_value_changed (GtkSpinButton *spin) { g_print ("%f\n", gtk_spin_button_get_value (spin)); } int main(int argc, char **argv) { GtkWidget *window1; GtkObject *spinbutton1_adj; GtkWidget *spinbutton1; gtk_init (&argc, &argv); window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* Note that we use 3 decimal places here, but only 2 are shown in the spinbutton. */ spinbutton1_adj = gtk_adjustment_new (1, 0, 100, 0.123, 10, 10); spinbutton1 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton1_adj), 1, 2); gtk_widget_show (spinbutton1); gtk_container_add (GTK_CONTAINER (window1), spinbutton1); g_signal_connect ((gpointer) spinbutton1, "value_changed", G_CALLBACK (on_spinbutton1_value_changed), NULL); gtk_widget_show (window1); gtk_main (); return 0; }
Created attachment 71534 [details] Output from gdb for cases where spinbutton works and another when it emits two value_changed signals
I have the same problem with a little pdf gtk program I am developing for my pda with GPE. I am first running on my desktop with gtk+-2.8.20 and developing with glade. My spinbutton for page changing works sometimes but seems to emit two value_changed signals for certain numbers when using the mouse button. I am dealing with simple integers numbers and I dont think there is anything wrong with the precision. When using the cursor keys to increase it all works fine. I have run the program with gdb and got output for both cases and the two emit signals for the broken case. Any help appreciated.
backtraces showing the multiple emissions after clicking + a few times Thread 1 "a.out" hit Breakpoint 1, 0x0000555555554bce in on_spinbutton1_value_changed () (ins)(gdb) bt
+ Trace 238474
Inferior 1 [process 28368] will be killed. (ins)Quit anyway? (y or n) y
so there are 2 paths to the breakpoint: #14 gtk_adjustment_set_value at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkadjustment.c line 567 #15 gtk_spin_button_real_spin at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkspinbutton.c line 1873 #16 start_spinning at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkspinbutton.c line 1400 #17 gtk_spin_button_button_press at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkspinbutton.c line 1425 #14 gtk_adjustment_set_value at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkadjustment.c line 567 #15 gtk_spin_button_set_value at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkspinbutton.c line 2314 #16 gtk_spin_button_update at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkspinbutton.c line 2637 #17 gtk_spin_button_focus_out at /home/daniel/jhbuild/checkout/gnome/gtk+-3/gtk/gtkspinbutton.c line 1295
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/252.