btn_negative 按下 对数字取负数进行运算 应该怎么填写 槽信号
btn_negative 按下 对数字取负数进行运算 应该怎么填写 槽信号
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
this->model = new class model;
this->tmp = "";
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_btn_0_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
if(this->str1!="")
{
QString str = "0";
str1.append(str);
ui->label_oper->setText(str1);
}
if(this->tmp != "")
{
this->tmp += this->ui->btn_0->text();
this->ui->lcd_display->display(this->tmp);
}
}
void Dialog::on_btn_1_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
_isNew = false;
str1 = "";
}
QString str = "1";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_1->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_2_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "2";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_2->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_3_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "3";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_3->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_4_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "4";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_4->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_5_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "5";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_5->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_6_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "6";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_6->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_7_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "7";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_7->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_8_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "8";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_8->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_9_clicked()
{
if(_isNew)
{
ui->label_oper->clear();
// _isNew = false;
str1 = "";
}
QString str = "9";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_9->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_C_clicked()
{
str1.clear();
this->ui->label_oper->clear();
this->tmp.clear();
this->ui->lcd_display->display(0);
}
void Dialog::on_btn_CE_clicked()
{
str1.clear();
this->ui->label_oper->clear();
this->tmp.clear();
this->ui->lcd_display->display(0);
}
void Dialog::on_btn_del_clicked()
{
this->ui->label_oper->clear();
tmp=tmp.left(tmp.length()-1);
this->ui->lcd_display->display(tmp);
}
void Dialog::on_btn_equal_clicked()
{
QString resul = this->model->doExpr_2();
//this->ui->label_oper->setText(resul);
QStringList Str_List = str1.split("");
Str_List[0] = Str_List[0].simplified();
arry[0] = Str_List[0].toDouble();
Str_List[2] = Str_List[2].simplified();
arry[2] = Str_List[2].toDouble();
// arry[0] = -arry[0];
float num = this->tmp.toFloat();
this->model->setNum2(num);
QString res = this->model->doExpr_1();
this->ui->lcd_display->display(res);
this->tmp = "";
_isNew = true;
}
void Dialog::on_btn_plus_clicked()
{
operat = '+';
QString str = " + ";
str1.append(str);
ui->label_oper->setText(str1);
oper='+';
ui->label_oper->setText(oper);
float num = this->tmp.toFloat();
this->model->setNum1(num);
this->tmp = "";
QString ex = this->ui->btn_plus->text();
this->ui->lcd_display->display(this->tmp);
this->model->setFlag(ex);
}
void Dialog::on_btn_sub_clicked()
{
operat = '-';
QString str = " - ";
str1.append(str);
ui->label_oper->setText(str1);
oper='-';
ui->label_oper->setText(oper);
float num = this->tmp.toFloat();
this->model->setNum1(num);
this->tmp = "";
QString ex = this->ui->btn_sub->text();
this->model->setFlag(ex);
}
void Dialog::on_btn_mul_clicked()
{
operat = '*';
QString str = " * ";
str1.append(str);
ui->label_oper->setText(str1);
oper='*';
ui->label_oper->setText(oper);
float num = this->tmp.toFloat();
this->model->setNum1(num);
this->tmp = "";
QString ex = this->ui->btn_mul->text();
this->model->setFlag(ex);
}
void Dialog::on_btn_div_clicked()
{
operat = '/';
QString str = " / ";
str1.append(str);
ui->label_oper->setText(str1);
oper='/';
ui->label_oper->setText(oper);
float num = this->tmp.toFloat();
this->model->setNum1(num);
this->tmp = "";
QString ex = this->ui->btn_div->text();
this->model->setFlag(ex);
}
void Dialog::on_btn_point_clicked()
{
QString str = ".";
str1.append(str);
ui->label_oper->setText(str1);
this->tmp += this->ui->btn_point->text();
this->ui->lcd_display->display(this->tmp);
}
void Dialog::on_btn_negative_clicked()
{
arry[0]=-arry[0];
arry[2]=-arry[2];
}