资源简介

这是用QT编写的只实现简单加减乘除运算的计算器,没有使用UI,界面纯手工。简单易懂,是初学者的良好引导者,程序完全可以运行成功。

资源截图

代码片段和文件信息

#include “calc.h“
#include 
#include 
#include 

Calc::Calc(QWidget *parent)
    : QWidget(parent)
{
   operator1=“0“;
   operator2=“0“;
    i=0;

    setWindowtitle(“calculator“);




            display=new QLineEdit(“0“);
            display->setReadOnly(true);
            display->setAlignment(Qt::AlignRight);
            display->setMaxLength(300);

            one=new QPushButton(“1“);
            two=new QPushButton(“2“);
            three=new QPushButton(“3“);
            four=new QPushButton(“4“);
            five=new QPushButton(“5“);
            six=new QPushButton(“6“);
            seven=new QPushButton(“7“);
            eight=new QPushButton(“8“);
            nine=new QPushButton(“9“);
            zero=new QPushButton(“0“);
            sub=new QPushButton(“-“);
            mul=new QPushButton(“*“);
            div=new QPushButton(“/“);
            equal=new QPushButton(“=“);
            add=new QPushButton(“+“);
            point=new QPushButton(“.“);
            clear=new QPushButton(“clear“);
            backspace=new QPushButton(“backspace“);



              connect(oneSIGNAL(clicked())thisSLOT(oneClicked()));
              connect(twoSIGNAL(clicked())thisSLOT(twoClicked()));
              connect(threeSIGNAL(clicked())thisSLOT(threeClicked()));
              connect(fourSIGNAL(clicked())thisSLOT(fourClicked()));
              connect(fiveSIGNAL(clicked())thisSLOT(fiveClicked()));
              connect(sixSIGNAL(clicked())thisSLOT(sixClicked()));
              connect(sevenSIGNAL(clicked())thisSLOT(sevenClicked()));
              connect(eightSIGNAL(clicked())thisSLOT(eightClicked()));
              connect(nineSIGNAL(clicked())thisSLOT(nineClicked()));
              connect(zeroSIGNAL(clicked())thisSLOT(zeroClicked()));
              connect(subSIGNAL(clicked())thisSLOT(subClicked()));
              connect(mulSIGNAL(clicked())thisSLOT(mulClicked()));
              connect(divSIGNAL(clicked())thisSLOT(divClicked()));
              connect(pointSIGNAL(clicked())thisSLOT(pointClicked()));
              connect(equalSIGNAL(clicked())thisSLOT(equalClicked()));
              connect(addSIGNAL(clicked())thisSLOT(addClicked()));
              connect(clearSIGNAL(clicked())thisSLOT(clearClicked()));
              connect(backspaceSIGNAL(clicked())thisSLOT(backspaceClicked()));



             QVBoxLayout  *mainlayout=new QVBoxLayout();
             QVBoxLayout *toplayout=new QVBoxLayout;
             toplayout->addWidget(display);
             QHBoxLayout *button1=new QHBoxLayout;
             button1->addWidget(one);
             button1->addWidget(two);
             button1->addWidget(three);
             button1->addWidget(four);

             QHBoxLayout *button2=new QHBoxLayout;
             button2->addWidget(five);
             button2->addWidget(six);
             button2->addWidget(seven);
             button2->addWidget(eight);

           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9699  2013-10-09 13:29  calc\calc.cpp

     文件       1206  2013-10-08 16:53  calc\calc.h

     文件        319  2013-10-05 15:19  calc\calce.pro

     文件      17744  2013-10-13 12:43  calc\calce.pro.user

     文件        164  2013-10-05 15:48  calc\main.cpp

    ..AD...         0  2013-10-13 12:43  calc

----------- ---------  ---------- -----  ----

                29132                    6


评论

共有 条评论