Results 1 to 5 of 5

Thread: What's wrong with my code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2011
    Location
    China Hunan province
    Posts
    7
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default What's wrong with my code?

    Code:
    **************************
    lcdrange.h:
    Qt Code:
    1. #ifndef LCDRANGE_H
    2. #define LCDRANGE_H
    3.  
    4. #endif // LCDRANGE_H
    5. #include<QWidget.h>
    6. #include<QSlider.h>
    7. #include<QLcdnumber.h>
    8.  
    9. class Lcdrange: public QWidget
    10. {
    11. Q_OBJECT
    12. public:
    13. Lcdrange();
    14. int value();
    15. private:
    16. QSlider* slider;
    17. QLCDNumber* lcd;
    18. public slots:
    19. void setValue(int);
    20. signals:
    21. void valueChanged(int);
    22. };
    To copy to clipboard, switch view to plain text mode 

    ***************************
    lcdrange.cpp:

    Qt Code:
    1. #include"lcdrange.h"
    2.  
    3. Lcdrange::Lcdrange()
    4. {
    5. slider=new QSlider(Qt::Horizontal,this);
    6. slider->setRange(0,99);
    7. slider->setGeometry(0,0,200,50);
    8.  
    9. lcd=new QLCDNumber(2,this);
    10. lcd->setGeometry(0,50,200,50);
    11.  
    12. connect(slider,SIGNAL(valueChanged(int)),lcd,SLOT(display(int)));
    13. connect(slider,SIGNAL(valueChanged(int)),SIGNAL(valueChanged(int)));
    14. }
    15.  
    16. int Lcdrange::value()
    17. {
    18. return slider->value();
    19. }
    20. void Lcdrange::setValue(int value)
    21. {
    22. return slider->setValue(value);
    23. }
    To copy to clipboard, switch view to plain text mode 


    ************************************
    main.cpp:
    Qt Code:
    1. #include<qapplication.h>
    2. #include<qpushbutton.h>
    3. #include"lcdrange.h"
    4.  
    5. class MyWindow: public Lcdrange
    6. {
    7. public:
    8. MyWindow();
    9. private:
    10. QPushButton* button;
    11. };
    12.  
    13. MyWindow::MyWindow()
    14. {
    15. setGeometry(200,150,200,250);
    16.  
    17. button=new QPushButton("Quit!",this);
    18. button->setGeometry(100,210,90,40);
    19.  
    20. Lcdrange* range=new Lcdrange;
    21. range->setGeometry(0,0,200,100);
    22.  
    23. Lcdrange* ranges=new Lcdrange;
    24. ranges->setGeometry(0,100,200,100);
    25.  
    26. connect(range,SIGNAL(valueChanged(int)),ranges,SLOT(setValue(int)));
    27. connect(button,SIGNAL(clicked()),qApp,SLOT(quit()));
    28. }
    29.  
    30. int main(int argc,char** argv)
    31. {
    32. QApplication a(argc,argv);
    33.  
    34. MyWindow mw;
    35.  
    36. mw.show();
    37. return a.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 9th August 2011 at 16:20.

Similar Threads

  1. What is wrong with this code?
    By Jeffb in forum Newbie
    Replies: 6
    Last Post: 18th February 2011, 07:35
  2. Qt Creator Green lines under everything suggesting all my code is wrong
    By Sydius in forum Qt Tools
    Replies: 1
    Last Post: 21st June 2010, 04:57
  3. What is wrong with my code?
    By Dante in forum Qt Programming
    Replies: 27
    Last Post: 6th April 2009, 07:56
  4. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47

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
  •  
Qt is a trademark of The Qt Company.