#ifndef TRYCALC_H
#define TRYCALC_H
#include <QtGui/QWidget>
#include "ui_trycalc.h"
{
Q_OBJECT
public:
~trycalc();
private:
Ui::trycalcClass ui;
public slots:
void addClicked(bool c = false);
void subClicked(bool c = false);
void mulClicked(bool c = false);
void divClicked(bool c = false);
};
#endif // TRYCALC_H
#include "trycalc.h"
#include <QMessageBox>
{
ui.setupUi(this);
connect(ui.pushButtonAdd,SIGNAL(clicked(bool c)),this,SLOT(addClicked(bool c;
}
trycalc::~trycalc()
{
}
//
void trycalc::addClicked(bool c)
{
QString qstring1
= ui.
lineEdit->text
();
QString qstring2
= ui.
lineEdit_2->text
();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2)
{
"missing or bad entry",
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3 = f1 + f2;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
void trycalc::subClicked(bool c)
{
QString qstring1
= ui.
lineEdit->text
();
QString qstring2
= ui.
lineEdit_2->text
();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2)
{
"missing or bad entry",
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3 = f1 - f2;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
void trycalc::mulClicked(bool c)
{
QString qstring1
= ui.
lineEdit->text
();
QString qstring2
= ui.
lineEdit_2->text
();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2)
{
"missing or bad entry",
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3 = f1 * f2;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
void trycalc::divClicked(bool c)
{
QString qstring1
= ui.
lineEdit->text
();
QString qstring2
= ui.
lineEdit_2->text
();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2
|| f2==0.)
{
"missing or bad entry",
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3;
if (f2 != 0.) f3 = f1 / f2;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
#ifndef TRYCALC_H
#define TRYCALC_H
#include <QtGui/QWidget>
#include "ui_trycalc.h"
class trycalc : public QWidget
{
Q_OBJECT
public:
trycalc(QWidget *parent = 0);
~trycalc();
private:
Ui::trycalcClass ui;
public slots:
void addClicked(bool c = false);
void subClicked(bool c = false);
void mulClicked(bool c = false);
void divClicked(bool c = false);
};
#endif // TRYCALC_H
#include "trycalc.h"
#include <QMessageBox>
trycalc::trycalc(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pushButtonAdd,SIGNAL(clicked(bool c)),this,SLOT(addClicked(bool c;
}
trycalc::~trycalc()
{
}
//
void trycalc::addClicked(bool c)
{
QString qstring1 = ui.lineEdit->text();
QString qstring2 = ui.lineEdit_2->text();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2)
{
QMessageBox mb("Adder",
"missing or bad entry",
QMessageBox::Warning,
QMessageBox::Ok ,
QMessageBox::NoButton ,
QMessageBox::NoButton);
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3 = f1 + f2;
QString qstring3;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
void trycalc::subClicked(bool c)
{
QString qstring1 = ui.lineEdit->text();
QString qstring2 = ui.lineEdit_2->text();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2)
{
QMessageBox mb("Adder",
"missing or bad entry",
QMessageBox::Warning,
QMessageBox::Ok ,
QMessageBox::NoButton ,
QMessageBox::NoButton);
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3 = f1 - f2;
QString qstring3;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
void trycalc::mulClicked(bool c)
{
QString qstring1 = ui.lineEdit->text();
QString qstring2 = ui.lineEdit_2->text();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2)
{
QMessageBox mb("Adder",
"missing or bad entry",
QMessageBox::Warning,
QMessageBox::Ok ,
QMessageBox::NoButton ,
QMessageBox::NoButton);
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3 = f1 * f2;
QString qstring3;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
void trycalc::divClicked(bool c)
{
QString qstring1 = ui.lineEdit->text();
QString qstring2 = ui.lineEdit_2->text();
bool ok1 = true;
bool ok2 = true;
float f1 = qstring1.toFloat(&ok1);
float f2 = qstring2.toFloat(&ok2);
if( qstring1.length() == 0
|| qstring2.length() == 0
|| !ok1
|| !ok2
|| f2==0.)
{
QMessageBox mb("Adder",
"missing or bad entry",
QMessageBox::Warning,
QMessageBox::Ok ,
QMessageBox::NoButton ,
QMessageBox::NoButton);
mb.exec();
ui.lineEdit->clear();
ui.lineEdit_2->clear();
ui.lineEdit_3->clear();
return;
}
float f3;
if (f2 != 0.) f3 = f1 / f2;
QString qstring3;
qstring3.setNum(f3);
ui.lineEdit_3->setText(qstring3);
}
To copy to clipboard, switch view to plain text mode
Bookmarks