GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 16, 2014 9:29 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: gtk spin button
PostPosted: Thu Sep 06, 2012 1:37 pm 
Offline
Familiar Face

Joined: Sat Apr 14, 2012 5:42 pm
Posts: 6
Here is some code I have trouble with from the offical reference manual
http://developer.gnome.org/gtk3/stable/GtkSpinButton.html

Code:
/* Provides a function to retrieve a floating point value from a
* GtkSpinButton, and creates a high precision spin button.
*/

gfloat
grab_float_value (GtkSpinButton *button,
                  gpointer       user_data)
{
  return gtk_spin_button_get_value (button);
}

void
create_floating_spin_button (void)
{
  GtkWidget *window, *button;
  GtkAdjustment *adjustment;

  adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 5);

  /* creates the spinbutton, with three decimal places */
  button = gtk_spin_button_new (adjustment, 0.001, 3);
  gtk_container_add (GTK_CONTAINER (window), button);

  gtk_widget_show_all (window);
}

The error I get while building is:
Quote:
1>c:\users\arbeit\documents\visual studio 2010\projects\gtk_training2\gtk_training2\gtk_training2.cpp(11): warning C4244: 'return': Konvertierung von 'gdouble' in 'gfloat', möglicher Datenverlust
1>c:\users\arbeit\documents\visual studio 2010\projects\gtk_training2\gtk_training2\gtk_training2.cpp(20): error C2440: '=': 'GtkObject *' kann nicht in 'GtkAdjustment *' konvertiert werden
1> Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.


Top
 Profile  
 
 Post subject: Re: gtk spin button
PostPosted: Thu Sep 06, 2012 2:13 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Hi,

It looks like you are trying to compile with a C++ compiler. It is much stricter than a C compiler and there are differences between the languages.

The first warning indicates that you are converting from a gdouble to a gfloat so may lose some digits if the value of the gdouble is larger than can be stored in the gfloat. The error is caused by the gtk_adjustment_new() returning a GtkObject * and not a GtkAdjustment * and there is no automatic conversion. This value needs to be cast to the correct type.

You do not say which version of GTK+ you are using as there are differences between GTK+ v2 and GTK+ v3. Seeing that your paths for the error messages are Windows paths I would presume GTK+ v2.

Take a look at this FAQ which has a small section on using the library with C++ http://developer.gnome.org/gtk/stable/gtk-question-index.html. And have a look at http://developer.gnome.org/gtk/stable/GtkSpinButton.html for the GTK+ v2 version.

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtk spin button
PostPosted: Thu Sep 06, 2012 2:18 pm 
Offline
Familiar Face

Joined: Sat Apr 14, 2012 5:42 pm
Posts: 6
thanks for the quick repy


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group