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

资源简介

用QT designer编辑的一个计算器,希望对大家有用,功能简单,适合同学们上交作业使用

资源截图

代码片段和文件信息

/*
 * =====================================================================================
 *
 *       Filename:  calculator.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  08/25/2010 09:20:15 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  TimBerWolF (ALL) 455436750@qq.com
 *        Company:  http://hi.baidu.com/witwolf/space
 *
 * =====================================================================================
 */

#include“calculator.h“
#include
calculator::calculator(QWidget *parent)
:QDialog(parent){
setupUi(this);
level3=QRegExp(“[(]{11}.*[)]{11}“);
level2=QRegExp(“(\\d+\\.?\\d+)[*/]{11}(\\d+\\.?\\d+)“);
level1=QRegExp(“(\\d+\\.?\\d+)[+-]{11}(\\d+\\.?\\d+)“);
b=true;
//将单目运算变成双目运算(取负)表达式中所有“(-“换成“(0-“
rep=QRegExp(“[(]{11}[-]{11}“);
connect(quitSIGNAL(clicked())thisSLOT(close()));
connect(ACSIGNAL(clicked())resSLOT(clear()));
connect(ACSIGNAL(clicked())labelSLOT(clear()));
connect(oneSIGNAL(clicked())thisSLOT(oneClick()));
connect(twoSIGNAL(clicked())thisSLOT(twoClick()));
connect(threeSIGNAL(clicked())thisSLOT(threeClick()));
connect(fourSIGNAL(clicked())thisSLOT(fourClick()));
connect(fiveSIGNAL(clicked())thisSLOT(fiveClick()));
connect(sixSIGNAL(clicked())thisSLOT(sixClick()));
connect(sevenSIGNAL(clicked())thisSLOT(sevenClick()));
connect(eightSIGNAL(clicked())thisSLOT(eightClick()));
connect(nineSIGNAL(clicked())thisSLOT(nineClick()));
connect(zeroSIGNAL(clicked())thisSLOT(zeroClick()));
connect(addSIGNAL(clicked())thisSLOT(addClick()));
connect(minusSIGNAL(clicked())thisSLOT(minusClick()));
connect(multiplySIGNAL(clicked())thisSLOT(multiplyClick()));
connect(divideSIGNAL(clicked())thisSLOT(divideClick()));
connect(lBracketSIGNAL(clicked())thisSLOT(lBracketClick()));
connect(rBracketSIGNAL(clicked())thisSLOT(rBracketClick()));
connect(dotSIGNAL(clicked())thisSLOT(dotClick()));
connect(backSpaceSIGNAL(clicked())thisSLOT(backSpaceClick()));
connect(calculateSIGNAL(clicked())thisSLOT(calculateClick()));
}
void calculator::oneClick(){
res->setText(res->text()+tr(“1“));
}
void calculator::twoClick(){
res->setText(res->text()+tr(“2“));
}
void calculator::threeClick(){
res->setText(res->text()+tr(“3“));
}
void calculator::fourClick(){
res->setText(res->text()+tr(“4“));
}
void calculator::fiveClick(){
res->setText(res->text()+tr(“5“));
}
void calculator::sixClick(){
res->setText(res->text()+tr(“6“));
}
void calculator::sevenClick(){
res->setText(res->text()+tr(“7“));
}
void calculator::eightClick(){
res->setText(res->text()+tr(“8“));
}
void calculator::nineClick(){
res->setText(res->text()+tr(“9“));
}
void calculator::zeroClick(){
res->setText(res->text()+tr(“0“));
}
void calculator::lBracketClick(){
res->setText(res->text()+tr(“(“));
}
void calculator::rBracketClick(){
res->setText(res->text()+tr(“)“));
}
void calculator::addClick(){

评论

共有 条评论