Results 1 to 5 of 5

Thread: Please help. Converter Dec to bin and Hex

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Please help. Converter Dec to bin and Hex

    Hi

    Please help I'm new to QT4, I need to write a program to accept a interger in QLineEdit and the Covert QPushButton should convert the decimal into binary and hex display them in the QLCDNumber fields. The clearAll QpushButton should also clear all the fields. This is what I have written thus far. I cant get the convert function to work:

    Converter.h file

    Qt Code:
    1. #ifndef CONVERTER_H
    2. #define CONVERTER_H
    3.  
    4. #include <QMainWindow>
    5. #include <QApplication>
    6. #include <QPushButton>
    7. #include <QTextEdit>
    8. #include <QVBoxLayout>
    9. #include <QDebug>
    10. #include <QLabel>
    11. #include <QLineEdit>
    12. #include <QLCDNumber>
    13. #include <QWidget>
    14.  
    15. class QLineEdit;
    16.  
    17. class Converter : public QWidget {
    18. Q_OBJECT
    19.  
    20. public:
    21. Converter();
    22. private:
    23. QLineEdit* decEdit;
    24. QLCDNumber* binLCD;
    25. QLCDNumber* hexLCD;
    26. QPushButton* c_Button;
    27. QPushButton* cl_Button;
    28. private slots:
    29. void convert(const QString&);
    30.  
    31. };
    32.  
    33. #endif // CONVERTER_H
    To copy to clipboard, switch view to plain text mode 



    Converter.cpp file

    Qt Code:
    1. #include "Converter.h"
    2. #include <QApplication>
    3. #include <QPushButton>
    4. #include <QTextEdit>
    5. #include <QVBoxLayout>
    6. #include <QDebug>
    7. #include <QLabel>
    8. #include <QLineEdit>
    9. #include <QLCDNumber>
    10. #include <QGridLayout>
    11.  
    12.  
    13. Converter::Converter()
    14. {
    15. QVBoxLayout *mainLayout = new QVBoxLayout(this);
    16. QGridLayout * editLayout = new QGridLayout;
    17. QHBoxLayout *ButtonLayout = new QHBoxLayout;
    18.  
    19. mainLayout -> addLayout(editLayout);
    20. mainLayout -> addStretch();
    21. mainLayout -> addLayout(ButtonLayout);
    22.  
    23. QLabel *decLabel = new QLabel(tr("Enter an Interger"));
    24. QLabel *binLabel = new QLabel(tr("Binary"));
    25. QLabel *hexLabel = new QLabel(tr("Hexadecimal"));
    26. decEdit = new QLineEdit;
    27. hexLCD = new QLCDNumber();
    28. binLCD = new QLCDNumber();
    29. c_Button = new QPushButton("&Convert");
    30. cl_Button = new QPushButton("&ClearAll");
    31.  
    32. editLayout ->addWidget(decLabel,0,0);
    33. editLayout ->addWidget(decEdit,0,1);
    34. editLayout ->addWidget(binLabel,1,0);
    35. editLayout ->addWidget(binLCD,1,1);
    36. editLayout ->addWidget(hexLabel,2,0);
    37. editLayout ->addWidget(hexLCD,2,1);
    38. editLayout ->addWidget(c_Button,0,2);
    39. editLayout ->addWidget(cl_Button,4,1);
    40.  
    41. this ->setWindowTitle("Decimal to Bin/Hex Converter");
    42.  
    43. connect(c_Button,SIGNAL(clicked()),this, SLOT(convert(QString)));
    44. connect(cl_Button,SIGNAL(clicked()),this, SLOT(clearAll()));
    45. }
    46.  
    47. void Converter::convert(const QString& newValue)
    48. {
    49.  
    50. int num = newValue.toInt();
    51.  
    52. //hexLCD->setHexMode(newValue);
    53. // binLCD->setHexMode(QString::number(num,2));
    54.  
    55. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp file

    Qt Code:
    1. #include<QApplication>
    2. #include"Converter.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc,argv);
    7. Converter c;
    8. c.setAttribute(Qt::WA_QuitOnClose);
    9. c.show();
    10. return app.exec();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 29th March 2011 at 10:39. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Please help. Converter Dec to bin and Hex

    setHexMode does not take any value.
    It only sets the mode of the LCD display to hexadecimal.

    You can do the same for a binary display by using setBinMode.

    You set the actual number via another function. See the documentation.

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Please help. Converter Dec to bin and Hex

    Where can download the documentation from?

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Please help. Converter Dec to bin and Hex

    If you installed the full SDK then you have it already either in designer or creator.
    Or, you can go online at: http://doc.qt.nokia.com/latest/classes.html
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Please help. Converter Dec to bin and Hex


Similar Threads

  1. PDF to Image Converter
    By RajabNatshah in forum Qt Programming
    Replies: 16
    Last Post: 23rd May 2024, 07:03
  2. Unit Converter Widget
    By baray98 in forum Qt Programming
    Replies: 13
    Last Post: 17th December 2016, 16:06
  3. QTest to NUnit, MBUnit or MSTest format xml converter
    By ralphing in forum Qt Programming
    Replies: 1
    Last Post: 7th September 2010, 09:16
  4. Image Converter
    By deekayt in forum General Discussion
    Replies: 1
    Last Post: 30th October 2006, 21:13

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.