Results 1 to 2 of 2

Thread: Problem reimplementing QSpinBox in a custom widget

  1. #1
    Join Date
    Mar 2006
    Posts
    74
    Thanks
    1
    Qt products
    Qt3
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem reimplementing QSpinBox in a custom widget

    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:
    Qt Code:
    1. #include "qspinbox.h"
    2.  
    3. class GammaSpinBox: public QSpinBox {
    4.  
    5. Q_OBJECT
    6.  
    7. public:
    8.  
    9. GammaSpinBox(QWidget * parent = 0, const char * name = 0 );
    10.  
    11. QString mapValueToText( int value );
    12.  
    13. int mapTextToValue( bool *ok );
    14.  
    15. };
    To copy to clipboard, switch view to plain text mode 

    and here is my iplementation:

    Qt Code:
    1. #include "gammaspinbox.h"
    2.  
    3. class GammaSpinBox : public QSpinBox
    4. {
    5. Q_OBJECT
    6. public:
    7.  
    8. GammaSpinBox(QWidget * parent = 0, const char * name = 0 ) : QSpinBox(161, 400, 1, parent, name)
    9. {
    10. }
    11.  
    12. QString mapValueToText( int value )
    13. {
    14.  
    15. return QString( "%1.%2" ) // 1.61 to 4.00
    16. .arg( value / 100 ).arg( value % 100 );
    17. }
    18.  
    19. int mapTextToValue( bool *ok )
    20. {
    21.  
    22. return (int) ( 100 * text().toFloat() );
    23. }
    24. };
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. build/linux/gammaqt/uic_setgammabase.cc: In constructor `SetGammaBase::SetGammaBase(QWidget*, const char*, bool, uint)':
    2. build/linux/gammaqt/uic_setgammabase.cc:2459: error: invalid use of undefined type `struct GammaSpinBox'
    3. ....
    4. build/linux/gammaqt/setgammabase.h:21: error: forward declaration of `struct GammaSpinBox'
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Problem reimplementing QSpinBox in a custom widget

    Oh..why are you decalre class again in inplemantation file
    a life without programming is like an empty bottle

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2006, 09:20
  2. Replies: 4
    Last Post: 24th March 2006, 23:50
  3. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 12:55
  4. Replies: 16
    Last Post: 7th March 2006, 16:57
  5. Replies: 4
    Last Post: 2nd March 2006, 00:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.