|
—
本帖被 XChinux 从 论坛管理区 移动到本区(2013-03-14)
—
- //Calculator.h
- #ifndef CALCULATOR_H
- #define CALCULATOR_H
- #include <QtGui>
- class Calculator : public QDialog
- {
- Q_OBJECT
- public:
- Calculator(QWidget *parent = 0);
- private:
- void CreateButton();
- QPushButton*ZERO;
- QPushButton*ONE;
- QPushButton*TWO;
- QPushButton*THREE;
- QPushButton*FOUR;
- QPushButton*FIVE;
- QPushButton*SIX;
- QPushButton*SEVEN;
- QPushButton*EIGHT;
- QPushButton*NINE;
- QPushButton*PI;
- QPushButton*E;
- QPushButton*ADD;
- QPushButton*SUBTRACTION;
- QPushButton*MULTIPLICATION;
- QPushButton*DIVISION;
- QPushButton*EQUALITY;
- QPushButton*DOT;
- QLineEdit*SCREEN;
- };
- #endif // CALCULATOR_H
- //Calculator.cpp
- #include "Calculator.h"
- Calculator::Calculator(QWidget*parent)
- {
- CreateButton();
- QVBoxLayout*V = new QVBoxLayout;
- QHBoxLayout*H1 = new QHBoxLayout;
- QHBoxLayout*H2 = new QHBoxLayout;
- QHBoxLayout*H3 = new QHBoxLayout;
- QHBoxLayout*H4 = new QHBoxLayout;
- QHBoxLayout*H5 = new QHBoxLayout;
- H1->addWidget(NINE);
- H1->addWidget(EIGHT);
- H1->addWidget(SEVEN);
- H1->addWidget(SIX);
- H2->addWidget(FIVE);
- H2->addWidget(FOUR);
- H2->addWidget(THREE);
- H2->addWidget(TWO);
- H3->addWidget(ONE);
- H3->addWidget(ZERO);
- H3->addWidget(PI);
- H3->addWidget(E);
- H4->addWidget(ADD);
- H4->addWidget(SUBTRACTION);
- H4->addWidget(MULTIPLICATION);
- H4->addWidget(DIVISION);
- H5->addWidget(DOT);
- H5->addWidget(EQUALITY);
- V->addWidget(SCREEN);
- V->addLayout(H1);
- V->addLayout(H2);
- V->addLayout(H3);
- V->addLayout(H4);
- V->addLayout(H5);
- setLayout(V);
- }
- void Calculator::CreateButton()
- {
- ZERO = new QPushButton("0",this);
- ONE = new QPushButton("1",this);
- TWO = new QPushButton("2",this);
- THREE = new QPushButton("3",this);
- FOUR = new QPushButton("4",this);
- FIVE = new QPushButton("5",this);
- SIX = new QPushButton("6",this);
- SEVEN = new QPushButton("7",this);
- EIGHT = new QPushButton("8",this);
- NINE = new QPushButton("9",this);
- PI = new QPushButton("pi",this);
- E = new QPushButton("e",this);
- ADD = new QPushButton("+",this);
- SUBTRACTION = new QPushButton("-",this);
- MULTIPLICATION = new QPushButton("*",this);
- DIVISION = new QPushButton("/",this);
- EQUALITY = new QPushButton("=",this);
- DOT = new QPushButton(".",this);
- SCREEN = new QLineEdit(this);
- }
- //main.cpp
- #include <QApplication>
- #include "Calculator.h"
- int main(int argc,char*argv[])
- {
- QApplication app(argc,argv);
- Calculator calcu;
- calcu.show();
- return app.exec();
- }
编译后提示 Configuration unchanged, skipping QMake step.Starting: E:/Qt/mingw/bin/mingw32-make.exe debug -w mingw32-make: Entering directory `D:/Documents/Qt/Calculator'E:/Qt/mingw/bin/mingw32-make -f Makefile.Debugmingw32-make[1]: Entering directory `D:/Documents/Qt/Calculator'mingw32-make[1]: Nothing to be done for `first'.mingw32-make[1]: Leaving directory `D:/Documents/Qt/Calculator'mingw32-make: Leaving directory `D:/Documents/Qt/Calculator'Exited with code 0.窗口闪了一下就消失了,帮帮忙!!!急求啊!!!!
|