当前位置:网站首页>C1-qt idea of realizing simple calculator 2021.10.15
C1-qt idea of realizing simple calculator 2021.10.15
2022-06-22 02:44:00 【Morning and evening rain】
Qt Implement a simple calculator
1. The goal is
Realization 1 2 3 4 A calculator for the sum of four numbers , Provide ideas and help for the realization of a complete calculator .
2. The code is as follows
.h Two variables are defined in the file
QString str;
QStringlist list;
.cpp Initializes two variables in the constructor of
str.clear();
list.clear();
.cpp The go to slot function of each button implemented in is as follows
void calculator::on_btn_1_clicked()// Button “1”
{
str+="1";
ui->edit_Input->setText(str);
}
void calculator::on_btn_2_clicked()// Button “2”
{
str+="2";
ui->edit_Input->setText(str);
}
void calculator::on_btn_3_clicked()// Button “3”
{
str+="3";
ui->edit_Input->setText(str);
}
void calculator::on_btn_4_clicked()// Button “4”
{
str+="4";
ui->edit_Input->setText(str);
}
void calculator::on_btn_plus_clicked()// Button “+”
{
list.insert(0,str);
str.clear();
list.insert(1,"+");
ui->edit_Input->setText(str);
}
void calculator::on_btn_result_clicked()// Button “=”
{
if(list.count()==2){
list.insert(2,str);
if(list.at(1)=="+"){
int v3 = QString(list.at(0)).toInt()+QString(list.at(2)).toInt();
ui->edit_Input->setText(QString::number(v3));
}
}
else
{
str.clear();
list.clear();
ui->edit_Input->setText(str);
}
}
3. effect

4. summary
1. Using string variables is easier than most people think of first .
2. On this basis , Encapsulate the concrete implementation of the slot function into a method ;
3. We can consider perfecting addition, subtraction, multiplication and division ;
边栏推荐
- Rely on the robustness of trusted AI to effectively identify deep forgery and help banks fight identity fraud
- [proteus simulation] INT0 and INT1 interrupt count
- Technical exploration: 360 digital subjects won the first place in the world in ICDAR OCR competition
- How to use tensorboard add_ histogram
- 关于PMP考试,你想知道的知识都在这里了
- 最新发布:Neo4j 图数据科学 GDS 2.0 和 AuraDS GA
- PMP备考相关敏捷知识
- Global exception handling
- fatal error: png++/png. Hpp: no that file or directory
- 微软 IE 浏览器于 6 月 15 日被永久关闭
猜你喜欢

MySQL recursively finds the tree structure. This method is very practical!

Rely on the robustness of trusted AI to effectively identify deep forgery and help banks fight identity fraud

Graphacademy course explanation: Fundamentals of neo4j graph data science

【6. 高精度乘法】

微软 IE 浏览器于 6 月 15 日被永久关闭

Live broadcast on June 22 | zhanzhihui, South China Institute of Technology: evolutionary computing for expensive optimization

基于xposed框架hook使用

自动化工具-监测文件的变化

GraphConnect 2022 大会的产品发布一览

Wechat applet film and television comment exchange platform system graduation design (3) background function
随机推荐
Transformation numérique des RH avec okr
Neo4j 智能供应链应用源代码简析
FPGA-Xilinx 7系列FPGA DDR3硬件设计规则
华阳智能冲刺深交所:拟募资4亿 复星惟盈是股东
最新发布:Neo4j 图数据科学 GDS 2.0 和 AuraDS GA
Graphacademy course explanation: Fundamentals of neo4j graph data science
DAST black box vulnerability scanner part 4: scanning performance
In 2022, the number of mobile banking users in Q1 will reach 650million, and ESG personal financial product innovation will be strengthened
微软 IE 浏览器于 6 月 15 日被永久关闭
C mapster object mapper learning
How to apply PMP project management knowledge?
Introduction to Apache ActiveMQ Artemis
[proteus simulation] INT0 and INT1 interrupt count
Anaconda historical version download
What programming does a child learn?
关于PMP考试,你想知道的知识都在这里了
Architecture and practice of vivo container cluster monitoring system
Rely on the robustness of trusted AI to effectively identify deep forgery and help banks fight identity fraud
June25,2022 PMP Exam clearance manual-4
自动化工具-监测文件的变化