QT计算器功能的实现
生活随笔
收集整理的這篇文章主要介紹了
QT计算器功能的实现
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1新建mainwindow工程
main.cpp文件
mainwindow.cpp文件
#include "mainwindow.h" #include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow) {ui->setupUi(this);QObject::connect(ui->calButton,SIGNAL(clicked()),this,SLOT(calSlot())); }MainWindow::~MainWindow() {delete ui; } void MainWindow::calSlot() {int first=ui->firstLineEdit->text().toInt();int second=ui->secondLineEdit->text().toInt();int result=first+second;//setText show the result in the Line Editui->resultLineEdit->setText(QString::number(result));}mainwindow.h文件
#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:Ui::MainWindow *ui; private slots:void calSlot();};#endif // MAINWINDOW_H總結(jié)
以上是生活随笔為你收集整理的QT计算器功能的实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 作者:谢波峰(1976-),男,中国人民
- 下一篇: 作者:张澄(1979-),男,中国联合网