PDA

View Full Version : Problem reimplementing QSpinBox in a custom widget



hvengel
30th March 2006, 02:10
I am trying to create a custom widget by reimplementing QSpingBox. The reason that I (think I) need to reimplement QSpinBox is because my values are floats not integers. So I need the spinbox to work with numbers between 1.61 and 4.0 and looking at the documentation for QSpinBox I need to reimplement mapValueToText and mapTextToValue to do this. Note this is not a plugin custom widget. Also I am using QT 3.3.4 at this time.

Here is my header file:


#include "qspinbox.h"

class GammaSpinBox: public QSpinBox {

Q_OBJECT

public:

GammaSpinBox(QWidget * parent = 0, const char * name = 0 );

QString mapValueToText( int value );

int mapTextToValue( bool *ok );

};

and here is my iplementation:


#include "gammaspinbox.h"

class GammaSpinBox : public QSpinBox
{
Q_OBJECT
public:

GammaSpinBox(QWidget * parent = 0, const char * name = 0 ) : QSpinBox(161, 400, 1, parent, name)
{
}

QString mapValueToText( int value )
{

return QString( "%1.%2" ) // 1.61 to 4.00
.arg( value / 100 ).arg( value % 100 );
}

int mapTextToValue( bool *ok )
{

return (int) ( 100 * text().toFloat() );
}
};

When I try to build my app with one of these widgets placed in a dialog in designer I get the following error messages:


build/linux/gammaqt/uic_setgammabase.cc: In constructor `SetGammaBase::SetGammaBase(QWidget*, const char*, bool, uint)':
build/linux/gammaqt/uic_setgammabase.cc:2459: error: invalid use of undefined type `struct GammaSpinBox'
....
build/linux/gammaqt/setgammabase.h:21: error: forward declaration of `struct GammaSpinBox'

The ui file is setgammabase.ui and line 21 of setgammabase.h is:

class GammaSpinBox;

Line 2459 in uic_setgammabase.cc is:

GammaR = new GammaSpinBox( ButtonGroup4_2, "GammaR" );

It is probably something real basic that I am doing wrong but I can't see what it is. Any ideas?

zlatko
30th March 2006, 08:12
Oh..why are you decalre class again in inplemantation file :eek: