#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
after="";
before="0";
showstr="";
op="";
}
MainWindow::~MainWindow()
{
delete ui;
}
//按键1
void MainWindow::on_pushButton_clicked()
{
after+="1";
showstr+="1";
print();
}
void MainWindow::on_pushButton_2_clicked()
{
after+="2";
showstr+="2";
print();
}
void MainWindow::on_pushButton_3_clicked()
{
after+="3";
showstr+="3";
print();
}
void MainWindow::on_pushButton_5_clicked()
{
after+="4";
showstr+="4";
print();
}
void MainWindow::on_pushButton_6_clicked()
{
after+="5";
showstr+="5";
print();
}
void MainWindow::on_pushButton_7_clicked()
{
after+="6";
showstr+="6";
print();
}
void MainWindow::on_pushButton_9_clicked()
{
after+="7";
showstr+="7";
print();
}
void MainWindow::on_pushButton_10_clicked()
{
after+="8";
showstr+="8";
print();
}
void MainWindow::on_pushButton_11_clicked()
{
after+="9";
showstr+="9";
print();
}
void MainWindow::on_pushButton_14_clicked()
{
after+="0";
showstr+="0";
print();
}
//计算过程
void MainWindow::process()
{
if(op=="")
{
before=after;
}
else if (op=="+")
{
int temp=after.toInt()+before.toInt();
qDebug()<<before.toInt()<<after.toInt();
before=QString::number(temp);
qDebug()<<before.toInt();
}
else if (op=="-")
{
int temp=before.toInt()-after.toInt();
qDebug()<<before.toInt()<<after.toInt();
before=QString::number(temp);
qDebug()<<before.toInt();
}
else if (op=="*")
{
int temp=after.toInt()*before.toInt();
qDebug()<<before.toInt()<<after.toInt();
before=QString::number(temp);
qDebug()<<before.toInt();
}
else if (op=="/")
{
if(after.toInt()==0)
{
QMessageBox::about(this,"error","can not / 0!");
return ;
}
int temp=before.toInt()/after.toInt();
qDebug()<<before.toInt()<<after.toInt();
before=QString::number(temp);
qDebug()<<before.toInt();
}
after="";
}
//print
void MainWindow::print()
{
ui->lineEdit->setText(showstr);
}
//+
void MainWindow::on_pushButton_4_clicked()
{
showstr+="+";
print();
qDebug()<<"+";
process();
op="+";
}
//-
void MainWindow::on_pushButton_8_clicked()
{
showstr+="-";
print();
qDebug()<<"-";
process();
op="-";
}
//*
void MainWindow::on_pushButton_12_clicked()
{
showstr+="*";
print();
qDebug()<<"*";
process();
op="*";
}
//\/
void MainWindow::on_pushButton_16_clicked()
{
showstr+="/";
print();
qDebug()<<"/";
process();
op="/";
}
//=
void MainWindow::on_pushButton_15_clicked()
{
showstr+="=";
process();
showstr+=before;
print();
showstr=after=before=op="";
}
//C
void MainWindow::on_pushButton_13_clicked()
{
ui->lineEdit->setText("");
}
带界面简单计算器程序Qt源代码
需积分: 22 60 浏览量
2017-10-27
13:45:08
上传
评论 7
收藏 4KB GZ 举报
ahaofan
- 粉丝: 192
- 资源: 1
最新资源
- 47-47.渗透测试-配置Kali Linux
- 卷积神经网络(Convolutional Neural Network,CNN)是一种深度学习模型
- DHT11温湿度传感器是一款常用的数字温湿度传感器,它结合了温度和湿度的测量功能,能够准确感知环境中的温度和湿度,并输出相应的数
- 45-45.渗透测试-天境漏洞扫描工具安装使用
- 基于PC817光耦隔离继电器模块PDF原理图+AD集成封装库文件.zip
- 当提及“奇怪的数列”时,我首先想到的是斐波那契数列和康托尔数列,这两个数列因其独特的生成规则和性质而显得与众不同 以下是关于这两
- hbase的安装与简单操作
- LAW100-AI大模型测试集
- Pandas 是一个功能强大的 Python 数据分析库
- Windows 安装docker.md
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈