欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

qt开发环境 - 丁林松教程,丑陋的计算器

发布时间:2023/12/15 68 豆豆
生活随笔 收集整理的这篇文章主要介绍了 qt开发环境 - 丁林松教程,丑陋的计算器 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

没有加入弹出窗口


#ifndef MAINWINDOW_H #define MAINWINDOW_H#include <QMainWindow>namespace Ui { class MainWindow; }class MainWindow : public QMainWindow {Q_OBJECTpublic:explicit MainWindow(QWidget *parent = 0);~MainWindow();private slots:void on_pushButton_clicked();private:Ui::MainWindow *ui; };#endif // MAINWINDOW_H


#include "mainwindow.h" #include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui->setupUi(this);QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(on_pushButton_clicked())); }MainWindow::~MainWindow() {delete ui;}void MainWindow::on_pushButton_clicked() {int first = ui->first->text().toInt();int second = ui->second->text().toInt();int result;switch (ui->comboBox->currentIndex()) {case 0:result = first + second;break;case 1:result = first - second;break;case 2:result = first * second;break;case 3:if(second < 0)return;result = first / second;break;default:break;} // int first = ui->first->text().toInt(); // int second = ui->second->text().toInt(); // int sum = first + second;ui->sum->setText(QString::number(result));}


总结

以上是生活随笔为你收集整理的qt开发环境 - 丁林松教程,丑陋的计算器的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。