当前位置:网站首页>QT - make a simple calculator - realize four operations
QT - make a simple calculator - realize four operations
2022-07-02 13:48:00 【Across mountains and rivers, across the sea】
Qt- Make a simple calculator - Realize four operations
Realization effect
Realization Add
Realization reduce
Realization ride
Realization except
How to complete ?
On the basis of the previous chapter , Delete +, Change to
This .
choice Editing project , Pictured.
Install the plus sign in the figure below , add to + ,- , * , / arithmetic
Code section

Complete code
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
private slots:
void calSlot();
};
#endif // MAINWINDOW_H
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp( Key code )
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(
//ui Inside calButton object ( Calculate button )
ui->calButton,
// Send a signal ( Click the signal )
SIGNAL(clicked()),
// Give the current object
this,
// With a slot function calSlot() To connect
SLOT(calSlot()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::calSlot()
{
int first=ui->firstLineEdit->text().
toInt();
int second=ui->secondLineEdit->text().
toInt();
int result;
if(ui->comboBox->currentIndex()==0){
//+
result=first+second;
ui->resultLineEdit->setText(QString::number(result));
}
if(ui->comboBox->currentIndex()==1){
//-
result=first-second;
ui->resultLineEdit->setText(QString::number(result));
}
if(ui->comboBox->currentIndex()==2){
//*
result=first*second;
ui->resultLineEdit->setText(QString::number(result));
}
if(ui->comboBox->currentIndex()==3){
// /
if(second==0)return;
result=first/second;
ui->resultLineEdit->setText(QString::number(result));
}
}
边栏推荐
- The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
- Web Foundation
- Sum of the first n terms of Fibonacci (fast power of matrix)
- Qt如何设置固定大小
- 操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
- What are the classifications of SSL certificates? How to choose the appropriate SSL certificate?
- Principle analysis of security rememberme
- 错误:EACCES:权限被拒绝,访问“/usr/lib/node_modules”
- [unity] using GB2312, the solution to abnormal program after packaging
- Why can't d link DLL
猜你喜欢

Web基础
![2022 zero code / low code development white paper [produced by partner cloud] with download](/img/46/92c51090e0c476df3bcffd2d11fb6d.png)
2022 zero code / low code development white paper [produced by partner cloud] with download

MAC (MacOS Monterey 12.2 M1) personal use PHP development

Essential for operation and maintenance - Elk log analysis system

(POJ - 1984) navigation nightare (weighted and search set)

题解《子数整数》、《欢乐地跳》、《开灯》

Téléchargement par navigateur

When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview

Error function ERF

Skillfully use SSH to get through the Internet restrictions
随机推荐
What are eNB, EPC and PGW?
Achievements in science and Technology (27)
2022 Heilongjiang provincial examination on the writing skills of Application Essays
Why is the default of switch followed by break?
The 29 year old programmer in Shanghai was sentenced to 10 months for "deleting the database and running away" on the day of his resignation!
I did it with two lines of code. As a result, my sister had a more ingenious way
[unity] using GB2312, the solution to abnormal program after packaging
OpenFOAM:lduMatrix&lduAddressing
[technology development-22]: rapid overview of the application and development of network and communication technology-2-communication Technology
基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】
[cloud native database] what to do when encountering slow SQL (Part 1)?
P3008 [usaco11jan]roads and planes g (SPFA + SLF optimization)
Dingtalk send message
不会看器件手册的工程师不是个好厨子
The xftp connection Haikang camera reported an error: the SFTP subsystem application has been rejected. Please ensure that the SFTP subsystem settings of the SSH connection are valid
石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
每日一题:1175.质数排列
口袋奇兵点评
selenium的特点
Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking





.
