Re: Help spinbuttons



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


2015-03-16 23:24 GMT-03:00 Roger Matthews <roger matthews 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`



$ ./page90.exe



(page90.exe:2614): Gtk-WARNING **: Attempting to add a
widget with type GtkSpinButton to a GtkWindow, but as a GtkBin subclass a
GtkWindow can only contain one widget at a time; it already contains a
widget
of type GtkSpinButton



(page90.exe:2614): GLib-GObject-WARNING **:
/build/buildd/glib2.0-2.38.1/./gobject/gsignal.c:2475: signal
'change-value' is
invalid for instance '0xee5350' of type 'GtkAdjustment'

Hello World

g_print Before gtk_main, integer 5

printf Before gtk_main, integer 5

printf Before gtk_main, double 0.500000*/


/*******************************************************************************/


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]