运行之后 怎样可以取消LCD哪里的运算过程 点击第二个数的时候 不要前面的 第一个数
运行之后 怎样可以取消LCD哪里的运算过程 点击第二个数的时候 不要前面的 第一个数
#include "widget.h"
#include "ui_widget.h"
#include
#include
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
this->num1=0;
this->num2=0;
}
Widget::~Widget()
{
delete ui;
}
void Widget::setNum1(int num)
{
num1=num;
}
void Widget::setNum2(int num)
{
num2=num;
}
void Widget::on_btnc_clicked()
{
this->str1.clear();
this->ui->lcdNumber->display(0);
this->ui->label->clear();
}
void Widget::on_btn1_clicked()
{
QString str = "1";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn2_clicked()
{
QString str = "2";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget:: on_btn3_clicked()
{
QString str = "3";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn4_clicked()
{
QString str = "4";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn5_clicked()
{
QString str = "5";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn6_clicked()
{
QString str = "6";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn7_clicked()
{
QString str = "7";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn8_clicked()
{
QString str = "8";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn9_clicked()
{
QString str = "9";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btn0_clicked()
{
QString str = "0";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btnp_clicked()
{
QString str = ".";
str1.append(str);
ui->lcdNumber->display(str1);
ui->label->setText(str1);
}
void Widget::on_btnadd_clicked()
{
oper = '+';
QString str = " + ";
str1.append(str);
ui->label->setText(str1);
}
void Widget::on_btnsub_clicked()
{
oper = '-';
QString str = " - ";
str1.append(str);
ui->label->setText(str1);
}
void Widget::on_btnplus_clicked()
{
oper = '*';
QString str = " * ";
str1.append(str);
ui->label->setText(str1);
}
void Widget::on_btndiv_clicked()
{
oper = '/';
QString str = " / ";
str1.append(str);
ui->label->setText(str1);
// oper = '/';
// ui->label->setText(flag);
// QString str = " / ";
// str1.append(str);
// ui->label->setText(str1);
// bool ok;
// int num =this->str1.toInt(&ok);
//this->setNum1(arry[0]);
// this->str1="";
//QString ex=ui->btndiv->setText(str);
// QString qoper=this->ui->btndiv->setText(flag);
// this->setNum1(arry[0]);
//this->setFlag(ex);
ui->label->setText(str1);
}
void Widget::on_btnback_clicked()
{
this->ui->label->clear();
str1=str1.left(str1.length()-1);
this->ui->lcdNumber->display(str1);
}
void Widget::on_btnequ_clicked()
{
QStringList Str_List = str1.split(" ");
Str_List[0] = Str_List[0].simplified();
arry[0] = Str_List[0].toDouble();
this->setNum2(arry[2]);
// arry[0]=num1;
Str_List[2] = Str_List[2].simplified();
arry[2] = Str_List[2].toDouble();
// arry[2]=num2;
// bool ok;
// int num =this->str1.toInt(&ok);
// this->setNum2(num);
// QString res=this->doExpr();
// this->ui->lcdNumber->display(res);
// this->str1="";
switch(oper)
{
case '+':
result = arry[0] + arry[2];
break;
case '-':
result = arry[0] - arry[2];
break;
case '*':
result = arry[0] * arry[2];
break;
case '/':
if (0 != arry[2])
result = arry[0] / arry[2];
else
result =0;
qDebug()<<"error";
break;
default:
break;
}
ui->lcdNumber->display(QString::number (result));
// ui->label->setText(QString::number (result));
}
void Widget::on_pushButton_2_clicked()
{
this->str1.clear();
this->ui->lcdNumber->display(0);
this->ui->label->clear();
}
// ui->lcdNumber->display(QString::number (result));
// ui->label->setText(QString::number (result));