Novice
29th March 2011, 08:47
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
#ifndef CONVERTER_H
#define CONVERTER_H
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QDebug>
#include <QLabel>
#include <QLineEdit>
#include <QLCDNumber>
#include <QWidget>
class QLineEdit;
class Converter : public QWidget {
Q_OBJECT
public:
Converter();
private:
QLineEdit* decEdit;
QLCDNumber* binLCD;
QLCDNumber* hexLCD;
QPushButton* c_Button;
QPushButton* cl_Button;
private slots:
void convert(const QString&);
};
#endif // CONVERTER_H
Converter.cpp file
#include "Converter.h"
#include <QApplication>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QDebug>
#include <QLabel>
#include <QLineEdit>
#include <QLCDNumber>
#include <QGridLayout>
Converter::Converter()
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QGridLayout * editLayout = new QGridLayout;
QHBoxLayout *ButtonLayout = new QHBoxLayout;
mainLayout -> addLayout(editLayout);
mainLayout -> addStretch();
mainLayout -> addLayout(ButtonLayout);
QLabel *decLabel = new QLabel(tr("Enter an Interger"));
QLabel *binLabel = new QLabel(tr("Binary"));
QLabel *hexLabel = new QLabel(tr("Hexadecimal"));
decEdit = new QLineEdit;
hexLCD = new QLCDNumber();
binLCD = new QLCDNumber();
c_Button = new QPushButton("&Convert");
cl_Button = new QPushButton("&ClearAll");
editLayout ->addWidget(decLabel,0,0);
editLayout ->addWidget(decEdit,0,1);
editLayout ->addWidget(binLabel,1,0);
editLayout ->addWidget(binLCD,1,1);
editLayout ->addWidget(hexLabel,2,0);
editLayout ->addWidget(hexLCD,2,1);
editLayout ->addWidget(c_Button,0,2);
editLayout ->addWidget(cl_Button,4,1);
this ->setWindowTitle("Decimal to Bin/Hex Converter");
connect(c_Button,SIGNAL(clicked()),this, SLOT(convert(QString)));
connect(cl_Button,SIGNAL(clicked()),this, SLOT(clearAll()));
}
void Converter::convert(const QString& newValue)
{
int num = newValue.toInt();
//hexLCD->setHexMode(newValue);
// binLCD->setHexMode(QString::number(num,2));
}
main.cpp file
#include<QApplication>
#include"Converter.h"
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
Converter c;
c.setAttribute(Qt::WA_QuitOnClose);
c.show();
return app.exec();
}
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
#ifndef CONVERTER_H
#define CONVERTER_H
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QDebug>
#include <QLabel>
#include <QLineEdit>
#include <QLCDNumber>
#include <QWidget>
class QLineEdit;
class Converter : public QWidget {
Q_OBJECT
public:
Converter();
private:
QLineEdit* decEdit;
QLCDNumber* binLCD;
QLCDNumber* hexLCD;
QPushButton* c_Button;
QPushButton* cl_Button;
private slots:
void convert(const QString&);
};
#endif // CONVERTER_H
Converter.cpp file
#include "Converter.h"
#include <QApplication>
#include <QPushButton>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QDebug>
#include <QLabel>
#include <QLineEdit>
#include <QLCDNumber>
#include <QGridLayout>
Converter::Converter()
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
QGridLayout * editLayout = new QGridLayout;
QHBoxLayout *ButtonLayout = new QHBoxLayout;
mainLayout -> addLayout(editLayout);
mainLayout -> addStretch();
mainLayout -> addLayout(ButtonLayout);
QLabel *decLabel = new QLabel(tr("Enter an Interger"));
QLabel *binLabel = new QLabel(tr("Binary"));
QLabel *hexLabel = new QLabel(tr("Hexadecimal"));
decEdit = new QLineEdit;
hexLCD = new QLCDNumber();
binLCD = new QLCDNumber();
c_Button = new QPushButton("&Convert");
cl_Button = new QPushButton("&ClearAll");
editLayout ->addWidget(decLabel,0,0);
editLayout ->addWidget(decEdit,0,1);
editLayout ->addWidget(binLabel,1,0);
editLayout ->addWidget(binLCD,1,1);
editLayout ->addWidget(hexLabel,2,0);
editLayout ->addWidget(hexLCD,2,1);
editLayout ->addWidget(c_Button,0,2);
editLayout ->addWidget(cl_Button,4,1);
this ->setWindowTitle("Decimal to Bin/Hex Converter");
connect(c_Button,SIGNAL(clicked()),this, SLOT(convert(QString)));
connect(cl_Button,SIGNAL(clicked()),this, SLOT(clearAll()));
}
void Converter::convert(const QString& newValue)
{
int num = newValue.toInt();
//hexLCD->setHexMode(newValue);
// binLCD->setHexMode(QString::number(num,2));
}
main.cpp file
#include<QApplication>
#include"Converter.h"
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
Converter c;
c.setAttribute(Qt::WA_QuitOnClose);
c.show();
return app.exec();
}