当前位置:网站首页>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 ;
边栏推荐
- FPGA Xilinx 7 Series FPGA DDR3 hardware design rules
- 【2. 归并排序】
- A short video costs hundreds of thousands of yuan, and the virtual digital man makes a circle with "strength"
- 【3.整数与浮点数二分】
- Chapter 24 image and video processing based on Simulink -- matlab in-depth learning and practical collation
- Live broadcast on June 22 | zhanzhihui, South China Institute of Technology: evolutionary computing for expensive optimization
- 银联支付 返回商户 Nignx post请求405
- Try catch of Bash
- Unity3d post process volume profile
- Graphacademy course explanation: Fundamentals of neo4j graph data science
猜你喜欢

Dernière publication: neo4j Graph Data Science GDS 2.0 et aurads ga

【2. 归并排序】

【7. 高精度除法】

Select for i/0 multiplexing

理想L9正式发布:8月底前开始交付 零售价45.98万元

如何选择合适的 Neo4j 版本(2022版)

C ++ Primer 第2章 变量和基本类型 总结

discuz! Bug in the VIP plug-in of the forum repair station help network: when the VIP member expires and the permanent member is re opened, the user group does not switch to the permanent member group

Wechat applet film and television comment exchange platform system graduation design completion (6) opening defense ppt

Pytorch visualization
随机推荐
Using OKR for HR digital transformation
【2. 归并排序】
2022 brazing test simulation 100 questions and answers
Ioerror: no translation files found for default language zh cn Solutions for
Game Jam开发周期
【Docekr学习遇到的坑】
国产品牌OPPO官方最新出品!这份PPT报告!真刷新我对它认知了
ATM机模拟系统
DAST black box vulnerability scanner part 4: scanning performance
Wechat applet film and television review and exchange platform system graduation design (1) development outline
Graphacademy course explanation: introduction to neo4j graph data science
C mapster object mapper learning
Cmake common command category notes
The neo4j skill tree was officially released to help you easily master the neo4j map database
从数据库的分类说起,一文了解图数据库
微软 IE 浏览器于 6 月 15 日被永久关闭
Database daily question - day 19: top ranked travelers
Which Amazon evaluation system is better?
EMC輻射發射整改-原理案例分析
All the knowledge you want to know about the PMP Exam is here