0
已解决
何文烁
中级守护
中级守护
整个heOS都基于QT(C++框架)编写
下面是项目中的can.cpp(计算器核心):
#include "can.h"
#include "ui_can.h"
#include<windows.h>
can::can(QWidget *parent)
: QWidget(parent)
, ui(new Ui::can)
{
ui->setupUi(this);
}
can::~can()
{
//setWindowOpacity(0.8);
delete ui;
}
int a,b,cnt=0,t1;
char tp;
QString mv="";
int getd(int lft)
{
return (mv.left(lft)).toInt();
}
int de(int a,int b,char tp)
{
switch (tp) {
case '+':
return a+b;
break;
case '-':
return a-b;
break;
case '*':
return a*b;
break;
case '/':
return a/b;
break;
default:
break;
}
return 0;
}
void can::on_toolButton_clicked()
{
mv+='1';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_2_clicked()
{
mv+='2';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_3_clicked()
{
mv+='3';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_4_clicked()
{
mv+='4';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_5_clicked()
{
mv+='5';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_6_clicked()
{
mv+='6';cnt++;
}
void can::on_toolButton_7_clicked()
{
mv+='7';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_8_clicked()
{
mv+='8';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_9_clicked()
{
mv+='9';cnt++;
ui->label->setText(mv);
}
void can::on_toolButton_10_clicked()
{
if(cnt==0)return;
mv+='0';
ui->label->setText(mv);
}
void can::on_toolButton_add_clicked()
{
mv+='+';
tp='+';
ui->label->setText(mv);
t1=mv.length();
a=getd(mv.length()-1);
}
void can::on_toolButton_rem_clicked()
{
mv+='-';
tp='-';
ui->label->setText(mv);
t1=mv.length();
a=getd(mv.length()-1);
}
void can::on_toolButton_che_clicked()
{
mv+='*';
tp='*';
ui->label->setText(mv);
t1=mv.length();
a=getd(mv.length()-1);
}
void can::on_toolButton_chu_clicked()
{
mv+='/';
tp='/';
ui->label->setText(mv);
t1=mv.length();
a=getd(mv.length()-1);
}
void can::on_toolButton_dy_clicked()
{
int ans;
b=mv.section(tp,1,1).toInt();
ans=de(a,b,tp);
ui->label->setText(QString::number(ans));
mv="";
}
void can::on_pushButtondll_clicked()
{
mv="";
ui->label->setText(mv);
}
void can::on_pushButtonbk_clicked()
{
mv=mv.chopped(1);
ui->label->setText(mv);
}
把用户的输入转成QString(跟string差不多),再分析,最后得出结果