• 大小: 51KB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2021-05-31
  • 语言: 其他
  • 标签: QT  计算器  

资源简介

用QT实现的简单计算器,包含加减乘除、开方、平方、求导、记忆等功能。

资源截图

代码片段和文件信息

#include “calculatorstandard.h“
#include “ui_calculatorstandard.h“

CalculatorStandard::CalculatorStandard(QWidget *parent) :
    QMainWindow(parent)
    ui(new Ui::CalculatorStandard)
{
    ui->setupUi(this);
    waitingForOperand = true;

    //0-9数字按键
    connect(ui->pushButton_ZeroSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_OneSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_TwoSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_ThreeSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_FourSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_FiveSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_SixSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_SevenSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_EightSIGNAL(clicked())thisSLOT(digitClicked()));
    connect(ui->pushButton_NineSIGNAL(clicked())thisSLOT(digitClicked()));
    //加减按键
    connect(ui->pushButton_AddSIGNAL(clicked())thisSLOT(addAndSubClicked()));
    connect(ui->pushButton_SubSIGNAL(clicked())thisSLOT(addAndSubClicked()));
    //乘除按键
    connect(ui->pushButton_MulSIGNAL(clicked())thisSLOT(MulAndDerivativeClicked()));
    connect(ui->pushButton_DivSIGNAL(clicked())thisSLOT(MulAndDerivativeClicked()));
    //等于号按键
    connect(ui->pushButton_EqualSIGNAL(clicked())thisSLOT(EqualClicked()));
    //清除按键
    connect(ui->pushButton_ClearSIGNAL(clicked())thisSLOT(clear()));
    connect(ui->pushButton_ClearAllSIGNAL(clicked())thisSLOT(clearAll()));
    //空格按键
    connect(ui->pushButton_BackspaceSIGNAL(clicked())thisSLOT(backspaceClicked()));
    //小数点按键
    connect(ui->pushButton_PointSIGNAL(clicked())thisSLOT(pointClicked()));
    //MC MR MS M+按键
    connect(ui->pushButton_MCSIGNAL(clicked())thisSLOT(MCclicked()));
    connect(ui->pushButton_MRSIGNAL(clicked())thisSLOT(MRclicked()));
    connect(ui->pushButton_MSSIGNAL(clicked())thisSLOT(MPlusclicked()));
    //正负切换按键
    connect(ui->pushButton_PlusminusSIGNAL(clicked())thisSLOT(plusMinusClicked()));
    //开方,平方,求导
    connect(ui->pushButton_DerivativeSIGNAL(clicked())thisSLOT(otherOperatorclicked()));
    connect(ui->pushButton_SqrtSIGNAL(clicked())thisSLOT(otherOperatorclicked()));
    connect(ui->pushButton_X_2SIGNAL(clicked())thisSLOT(otherOperatorclicked()));
}

CalculatorStandard::~CalculatorStandard()
{
    delete ui;
}

void CalculatorStandard::digitClicked ()
{
    //当某一个object emit一个signal的时候,它就是一个sender系统会记录下当前是谁emit出这个signal的,
    //所以你在对应的slot里就可以通过 sender()得到当前是谁invoke了你的slot,对应的是Qobject->d->sender.
    //有可能多个 object的signal会连接到同一个signal(例如多个Button可能会connect到一个slot函数onclick())
    //因此这是就 需要判断到底是哪个object emit了这个signal,根据sender的不同来进行不同的处理.
    QPushButton *clickedButton = qobject_cast(sender());
    //int digitValue = clickedButton->text().toInt();
    //qDebug()<< ui-

评论

共有 条评论