• 3768阅读
  • 4回复

[提问]很新的新手提问啊!!自己编的简单计算器 [复制链接]

上一主题 下一主题
离线witailab
 
只看楼主 倒序阅读 楼主  发表于: 2012-12-13


刚学Qt,看的是C++GUI Qt4,看完前5章。于是就想动手做做,但是在编译过程中遇到问题不会解决,所以就向网友求助了。
代码在下面
/********************************************************************************** Form generated from reading UI file 'calculator.ui'**** Created: Thu Dec 13 20:45:31 2012**      by: Qt User Interface Compiler version 4.8.3**** WARNING! All changes made in this file will be lost when recompiling UI file!********************************************************************************/
#ifndef UI_CALCULATOR_H#define UI_CALCULATOR_H
#include <QtCore/QVariant>#include <QtGui/QAction>#include <QtGui/QApplication>#include <QtGui/QButtonGroup>#include <QtGui/QComboBox>#include <QtGui/QHBoxLayout>#include <QtGui/QHeaderView>#include <QtGui/QLCDNumber>#include <QtGui/QSpinBox>#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Calculator{public:    QWidget *layoutWidget;    QHBoxLayout *horizontalLayout;    QSpinBox *spinBox_1;    QComboBox *comboBox;    QSpinBox *spinBox_2;    QLCDNumber *lcdNumber;
    void setupUi(QWidget *Calculator)    {        if (Calculator->objectName().isEmpty())            Calculator->setObjectName(QString::fromUtf8("Calculator"));        Calculator->resize(408, 161);        layoutWidget = new QWidget(Calculator);        layoutWidget->setObjectName(QString::fromUtf8("layoutWidget"));        layoutWidget->setGeometry(QRect(30, 40, 331, 61));        horizontalLayout = new QHBoxLayout(layoutWidget);        horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));        horizontalLayout->setContentsMargins(0, 0, 0, 0);        spinBox_1 = new QSpinBox(layoutWidget);        spinBox_1->setObjectName(QString::fromUtf8("spinBox_1"));
        horizontalLayout->addWidget(spinBox_1);
        comboBox = new QComboBox(layoutWidget);        comboBox->setObjectName(QString::fromUtf8("comboBox"));
        horizontalLayout->addWidget(comboBox);
        spinBox_2 = new QSpinBox(layoutWidget);        spinBox_2->setObjectName(QString::fromUtf8("spinBox_2"));
        horizontalLayout->addWidget(spinBox_2);
        lcdNumber = new QLCDNumber(layoutWidget);        lcdNumber->setObjectName(QString::fromUtf8("lcdNumber"));
        horizontalLayout->addWidget(lcdNumber);

        retranslateUi(Calculator);
        QMetaObject::connectSlotsByName(Calculator);    } // setupUi
    void retranslateUi(QWidget *Calculator)    {        Calculator->setWindowTitle(QApplication::translate("Calculator", "Form", 0, QApplication::UnicodeUTF8));        comboBox->clear();        comboBox->insertItems(0, QStringList()         << QApplication::translate("Calculator", "+", 0, QApplication::UnicodeUTF8)         << QApplication::translate("Calculator", "-", 0, QApplication::UnicodeUTF8)         << QApplication::translate("Calculator", "*", 0, QApplication::UnicodeUTF8)         << QApplication::translate("Calculator", "/", 0, QApplication::UnicodeUTF8)        );    } // retranslateUi
};
namespace Ui {    class Calculator: public Ui_Calculator {};} // namespace Ui
QT_END_NAMESPACE
#endif // UI_CALCULATOR_H

#ifndef CALCULATOR_H#define CALCULATOR_H
#include"ui_calculator.h"class Calculator:public QWidget{    Q_OBJECTpublic:    Calculator(QWidget *parent=0);private slots:    void inputSpinBox1_valueChange(int value);    void inputSpinBox2_valueChange(int value);private:    Ui::Calculator ui;}#endif // CALCULATOR_H
#include<QtGui>#include"calculator.h"Calculator::Calculator(QWidget *parent)    :QWidget(parent){    ui.setupUi(this);}void Calculator::inputSpinBox1_valueChange(int value){    if(ui.comboBox->currentIndex()==0)        ui.lcdNumber->display(QString::number(value+ui.spinBox_2->value()));    else if(ui.comboBox->currentIndex()==1)        ui.lcdNumber->display(QString::number(value-ui.spinBox_2->value()));    else if(ui.comboBox->currentIndex()==2)        ui.lcdNumber->display(QString::number(value*ui.spinBox_2->value()));    else        ui.lcdNumber->display(QString::number(value/ui.spinBox_2->value()));}void Calculator::inputSpinBox2_valueChange(int value){    if(ui.comboBox->currentIndex()==0)        ui.lcdNumber->display(QString::number(value+ui.spinBox_1->value()));    else if(ui.comboBox->currentIndex()==1)        ui.lcdNumber->display(QString::number(ui.spinBox_1->value()-value));    else if(ui.comboBox->currentIndex()==2)        ui.lcdNumber->display(QString::number(value*ui.spinBox_1->value()));    else        ui.lcdNumber->display(QString::number(ui.spinBox_1->value()/value));}
#include<QApplication>
#include"calculator.h"
int main(int argc,char *argv[]){    QApplication app(argc,argv);    Calculator calculator;    calculator.show();    return app.exec();}
离线witailab
只看该作者 1楼 发表于: 2012-12-13







离线gesturewei
只看该作者 2楼 发表于: 2012-12-13
楼主写Calculator类时把末尾的分号丢了
离线witailab
只看该作者 3楼 发表于: 2012-12-15
回 2楼(gesturewei) 的帖子
呃····居然是这种错误·····
谢谢你了·!!!
这学期刚把C++学完······
所以这些小问题·慢慢改进吧
离线gesturewei
只看该作者 4楼 发表于: 2012-12-16
回 3楼(witailab) 的帖子
C++还是需要细心和耐心的,所以加油!
快速回复
限100 字节
 
上一个 下一个