[c++]代码库
/*
* ������
* ʵ�ּ��������ù���
* ������ʵ�ֺ������Ĵ���
* ������Qt Creator
* Lzy 2011-8-26
*/
#include "widgetcounter.h"
#include "ui_widgetcounter.h"
#include <QObject>
#include <QString>
WidgetCounter::WidgetCounter(QWidget *parent) :
QWidget(parent),
ui(new Ui::WidgetCounter)
{
ui->setupUi(this);
ui->lEditPlay->setText("0"); //��ʼ�� ��ʾ0
num = num1 = num2 = 0;
f_point = f_num = false;
op = 0;
times = 1;
QObject::connect(this,SIGNAL(NumClick(int)), this, SLOT(Counter(int))); //�ź����۴�������
}
WidgetCounter::~WidgetCounter()
{
delete ui;
}
void WidgetCounter::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
/*��ֵ����*/
void WidgetCounter::Counter(int i)
{
if(!f_point)
{
if(!f_num)
{
num1 = num1 * 10 + i;
ui->lEditPlay->setText(QString::number(num1));
}
else
{
num2 = num2 * 10 + i;
ui->lEditPlay->setText(QString::number(num2));
}
}
else
{
times *= 10;
if(!f_num)
{
num1 = num1 + i/times;
ui->lEditPlay->setText(QString::number(num1));
}
else
{
num2 = num2 + i/times;
ui->lEditPlay->setText(QString::number(num2));
}
}
}
/*���ֽ�����*/
void WidgetCounter::on_Btn1_clicked()
{
emit NumClick(1);
}
void WidgetCounter::on_Btn2_clicked()
{
emit NumClick(2);
}
void WidgetCounter::on_Btn3_clicked()
{
emit NumClick(3);
}
void WidgetCounter::on_Btn4_clicked()
{
emit NumClick(4);
}
void WidgetCounter::on_Btn5_clicked()
{
emit NumClick(5);
}
void WidgetCounter::on_Btn6_clicked()
{
emit NumClick(6);
}
void WidgetCounter::on_Btn7_clicked()
{
emit NumClick(7);
}
void WidgetCounter::on_Btn8_clicked()
{
emit NumClick(8);
}
void WidgetCounter::on_Btn9_clicked()
{
emit NumClick(9);
}
void WidgetCounter::on_Btn0_clicked()
{
emit NumClick(0);
}
/*���ܼ�����*/
void WidgetCounter::on_BtnDev_clicked()
{
op = '/';
f_num = true;
f_point = false;
times = 1;
}
void WidgetCounter::on_BtnMul_clicked()
{
op = '*';
f_num = true;
f_point = false;
times = 1;
}
void WidgetCounter::on_BtnSub_clicked()
{
op = '-';
f_num = true;
f_point = false;
times = 1;
}
void WidgetCounter::on_BtnPlus_clicked()
{
op = '+';
f_num = true;
f_point = false;
times = 1;
}
/*��������*/
void WidgetCounter::on_BtnEql_clicked()
{
switch(op)
{
case '+':
num = num1 + num2;
break;
case '-':
num = num1 - num2;
break;
case '*':
num = num1 * num2;
break;
case '/':
num = num1 / num2;
break;
case 0:
num = num1;
}
ui->lEditPlay->setText(QString::number(num));
num1 = num;
num2 = 0;
op = 0;
times = 1;
}
/*С���㰴��*/
void WidgetCounter::on_BtnPoint_clicked()
{
f_point = true;
}
/*����������*/
void WidgetCounter::on_BtnC_clicked()
{
ui->lEditPlay->setText("0");
num1 = 0;
num2 = 0;
op = 0;
f_point = f_num = false;
times = 1;
}
void WidgetCounter::on_BtnBack_clicked()
{
if(!f_num)
{
ui->lEditPlay->backspace();
num1 = ui->lEditPlay->text().toDouble();
ui->lEditPlay->setText(QString::number(num1));
}
else
{
ui->lEditPlay->backspace();
num2 = ui->lEditPlay->text().toDouble();
ui->lEditPlay->setText(QString::number(num2));
}
}
void WidgetCounter::on_BtnCE_clicked()
{
if(f_num)
{
num2 = 0;
ui->lEditPlay->setText(QString::number(num2));
}
else if(op != 0)
op = 0;
else
{
num1 = 0;
ui->lEditPlay->setText(QString::number(num1));
}
}
[代码运行效果截图]
[源代码打包下载]
初级程序员
by: m 发表于:2016-03-16 19:37:27 顶(0) | 踩(0) 回复
怎么所有的程序都显示有一个错误呢,而且不显示错误在哪,怎么调试
回复评论