Hi Paulo, or anybody else interested in helping,
I've read chapter 2 of Foundations of GTK+ Development concerning signals and
callback functions as suggested (see below) but am still getting this error:
(page90v2.exe:2289): Gtk-CRITICAL **: gtk_spin_button_get_value: assertion
'GTK_IS_SPIN_BUTTON (spin_button)' failed
every time one of the up or down arrows in the spinbutton is pressed. Here is
the code:
#include stdio.h
#include gtk/gtk.h
/*double number_double;*/
static void get_new_number(GtkWidget *widget, gpointer spin_float)
{
/*number_double = */ gtk_spin_button_get_value(spin_float);
}
/*static void print_new_number(GtkWidget *widget, gpointer data)
{
printf(print_new_number %f\n, number_double);
}*/
int main(int argc, char *argv[])
{
GtkWidget *window, *spin_float;
GtkAdjustment *float_pt;
/*gdouble number_double;*/
gtk_init (argc, argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), Spin Buttons);
gtk_container_set_border_width (GTK_CONTAINER(window), 10);
gtk_widget_set_size_request (window, 150, 100);
float_pt = GTK_ADJUSTMENT (gtk_adjustment_new (0.5, 0.0, 1.0, 0.1, 0.5, 0.5));
spin_float = gtk_spin_button_new (float_pt, 0.1, 1);
gtk_container_add (GTK_CONTAINER (window), spin_float);
gtk_widget_show_all (window);
g_signal_connect (spin_float, value-changed, G_CALLBACK (get_new_number),
NULL);
/*g_signal_connect (window, value-changed, G_CALLBACK (print_new_number),
NULL);*/
printf(printf Before gtk_main, double %p\n, /*number_double*/spin_float);
gtk_main ();
printf(After gtk_main, double %p\n, /*number_double*/spin_float);
return 0;
}
//
/*
$ gedit page90v2.c
$ gcc `pkg-config --cflags gtk+-3.0` -o page90v2.exe page90v2.c `pkg-config
--libs gtk+-3.0`
$ ./page90.exe
(page90v2.exe:2289): Gtk-CRITICAL **: gtk_spin_button_get_value: assertion
'GTK_IS_SPIN_BUTTON (spin_button)' failed
(page90v2.exe:2289): Gtk-CRITICAL **: gtk_spin_button_get_value: assertion
'GTK_IS_SPIN_BUTTON (spin_button)' failed
^C
//
Paulo's reply:
Hello Roger.
I think you misunderstand the concept of callback functions. In your example
there is no appropriated callback function to deal with the changes of spin
button. And another thing, the 3rd parameters to register a callback function
must be a pointer.
I suggest to take a look at chapter 2 under Signals and Callbacks section.
José Paulo
/**/
My original email:
2015-03-16 23:24 GMT-03:00 Roger Matthews roger.matth...@hotmail.com:
/* I want a window containing many spinbuttons for both
integers and floating-point numbers, these may then be either 1) left
unchanged, or 2) changed to a new value. Then, whether changed or unchanged,
use the integers and floats as input parameters into various calculations. As
it is the printf() statements only show the unchanged values. */
/*The example below is taken from page 90 of
Foundations of GTK+ Development by Andrew Krause*/
#include stdio.h
#include gtk/gtk.h
int main(int argc, char *argv[])
{
GtkWidget *window, *spin_int, *spin_float;
GtkAdjustment *integer, *float_pt;
gint number_int;
gdouble number_double;
gtk_init (argc, argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), Spin Buttons);
gtk_container_set_border_width (GTK_CONTAINER(window), 10);
gtk_widget_set_size_request (window, 150, 100);
integer = GTK_ADJUSTMENT (gtk_adjustment_new (5.0, 0.0,
10.0, 1.0, 2.0, 2.0));
float_pt = GTK_ADJUSTMENT (gtk_adjustment_new (0.5, 0.0, 1.0,
0.1, 0.5, 0.5));
spin_int = gtk_spin_button_new (integer, 1.0, 0);
spin_float = gtk_spin_button_new (float_pt, 0.1, 1);
gtk_container_add (GTK_CONTAINER (window), spin_int);
gtk_container_add (GTK_CONTAINER (window), spin_float);
gtk_widget_show_all (window);
number_int=gtk_spin_button_get_value_as_int(spin_int);
number_double=gtk_spin_button_get_value(spin_float);
g_signal_connect(integer, change-value, G_CALLBACK (spin_int), number_int);
g_print (Hello World\n);
g_print(g_print Before gtk_main, integer %d\n, number_int);
printf(printf Before gtk_main, integer %d\n, number_int);
printf(printf Before gtk_main, double %f\n, number_double);
gtk_main ();
printf(Hello World\n);
printf(After gtk_main %d\n, number_int);
return 0;
}
//
/*Below are the commands to edit, compile and execute the
program, and the warnings, messages and output to the terminal. At this stage
the warnings are unimportant, I merely want to be able to read or save both the
unchanged and changed values displayed in the spinbutton(s).*/
/*
$ gedit page90.c
$ gcc `pkg-config --cflags gtk+-3.0` -o page90.exe page90.c
`pkg-config --libs gtk+-3.0`
$