Qt设计:简单的小计算器

##先看一下实现的效果
Qt设计:简单的小计算器_第1张图片

##细节
Qt设计:简单的小计算器_第2张图片

Qt设计:简单的小计算器_第3张图片

Qt设计:简单的小计算器_第4张图片

##mymainwindow.CPP

#include "mymainwindow.h"
#include "ui_mymainwindow.h"
#include "QString"
myMainWindow::myMainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::myMainWindow)
{
    ui->setupUi(this);
}

myMainWindow::~myMainWindow()
{
    delete ui;
}

void myMainWindow::on_spinBox_valueChanged(int arg1)
{
    bool ok;
      int index;
      QString n;
      QString a=ui->spinBox->text();
      QString b=ui->spinBox_2->text();
      int c=a.toInt(&ok);
      int d=b.toInt(&ok);
      index=ui->comboBox->currentIndex();
      switch(index)
      {
      case 0:
          {
              double f=c+d;
              ui->lineEdit->setText(n.setNum(f));
              break;
          }
      case 1:
          {
              double f=c-d;
              ui->lineEdit->setText(n.setNum(f));
              break;
          }
      case 2:
          {
              double f=c*d;
              ui->lineEdit->setText(n.setNum(f));
              break;
          }
      case 3:
          {
              double f=c/d;
              ui->lineEdit->setText(n.setNum(f));
              break;
          }
      }

}

void myMainWindow::on_spinBox_2_valueChanged(int arg1)
{
    bool ok;
        int index;
        QString n;
        QString a=ui->spinBox->text();
        QString b=ui->spinBox_2->text();
        int c=a.toInt(&ok);
        int d=b.toInt(&ok);
        index=ui->comboBox->currentIndex();
        switch(index)
        {
        case 0:
            {
                double f=c+d;
                ui->lineEdit->setText(n.setNum(f));
                break;
            }
        case 1:
            {
                double f=c-d;
                ui->lineEdit->setText(n.setNum(f));
                break;
            }
        case 2:
            {
                double f=c*d;
                ui->lineEdit->setText(n.setNum(f));
                break;
            }
        case 3:
            {
                double f=c/d;
                ui->lineEdit->setText(n.setNum(f));
                break;
            }
        }

}

void myMainWindow::on_pushButton_clicked()
{
    close();
}

##myMainWindow.h

#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H

#include 

namespace Ui {
class myMainWindow;
}

class myMainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit myMainWindow(QWidget *parent = 0);
    ~myMainWindow();

private slots:
    void on_spinBox_valueChanged(int arg1);

    void on_spinBox_2_valueChanged(int arg1);

    void on_pushButton_clicked();

private:
    Ui::myMainWindow *ui;
};

#endif // MYMAINWINDOW_H

##main.cpp

#include "mymainwindow.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    myMainWindow w;
    w.show();

    return a.exec();
}

你可能感兴趣的:(Qt)