当前位置: 首页 > news >正文

Qt+C++桌面计算器源码

 程序示例精选

Qt+C++桌面计算器源码

如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对<<Qt+C++桌面计算器源码>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


文章目录

一、所需工具软件

二、使用步骤

1. 引入库

2. 主要代码

3. 运行结果

三、在线协助

一、所需工具软件

1. VS, Qt

2. C++

二、使用步骤

1.引入库

代码如下(示例):


#include <QDebug>
#include <iostream>
#include <cmath>
#include <QChar>
#include <QDialog>
#include <QFile>

2.主要代码

代码如下(示例):


void MainWindow::Calc_Suffix()
{for(int i=0;i<out.size();i++){bool is_Num =true;out[i].toDouble(&is_Num);if(is_Num)//如果是数字,直接入栈{s2.push(out[i].toDouble(&is_Num));}else if(out[i]=='s'||out[i]=='c'||out[i]=='t'||out[i]=='^'){double x=s2.pop();if(out[i]=='s')x=sin(x);else if(out[i]=='c')x=cos(x);else if(out[i]=='t')x=tan(x);else if(out[i]=='l')x=log(x);else if(out[i]=='^'){int y=x;x=s2.pop();int z=x;for(int j=1;j<y;j++)x=x*z;}s2.push(x);}else if(out[i]=="+"||out[i]=="-"||out[i]=="*"||out[i]=="/")//如果是运算符,弹栈两次,并进行运算,运算后,结果入栈{double x=s2.pop();double y=s2.pop();if(out[i]=="+"){s2.push(y+x);}else if(out[i]=="-"){s2.push(y-x);}else if(out[i]=="*"){s2.push(y*x);}else if(out[i]=="/"){s2.push(y/x);}}}result = s2.pop();qDebug()<<result;
}void MainWindow::m_init()
{ba.clear();out.clear();
}void MainWindow::on_pushButton_clicked()
{in=ui->lineEdit->text();//获取表达式getChar();getSuffix();Calc_Suffix();ui->lineEdit->clear();//清空文本编辑框ui->lineEdit->setText(QString("%1%2").arg('=').arg(result));//显示结果m_init();
}void MainWindow::on_pushButton_2_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(0));
}void MainWindow::on_pushButton_3_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(1));
}void MainWindow::on_pushButton_4_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(2));
}void MainWindow::on_pushButton_5_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(3));
}void MainWindow::on_pushButton_6_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(4));
}void MainWindow::on_pushButton_7_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(5));
}void MainWindow::on_pushButton_8_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(6));
}void MainWindow::on_pushButton_9_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(7));
}void MainWindow::on_pushButton_10_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(8));
}void MainWindow::on_pushButton_11_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(9));
}void MainWindow::on_pushButton_12_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("+"));
}void MainWindow::on_pushButton_13_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("-"));
}void MainWindow::on_pushButton_14_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("*"));
}void MainWindow::on_pushButton_15_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("/"));
}void MainWindow::on_pushButton_20_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("."));
}void MainWindow::on_pushButton_18_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("("));
}void MainWindow::on_pushButton_19_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg(")"));
}void MainWindow::on_pushButton_16_clicked()
{//清空所有内容,并初始化ui->lineEdit->clear();m_init();
}void MainWindow::on_pushButton_17_clicked()
{//退格删除一个字符ui->lineEdit->backspace();
}void MainWindow::on_pushButton_21_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("sin"));
}void MainWindow::on_pushButton_22_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("cos"));
}void MainWindow::on_pushButton_23_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("tan"));
}void MainWindow::on_pushButton_24_clicked()//最小公倍数,c_mul
{QString str=ui->lineEdit->text();QString l1="0",l2="0";QByteArray yue = str.toLatin1();bool hasSpace = false;QString c_div="1";int max_yue;for(int i=0;i<yue.size();i++){char x=yue[i];if(x=='.')hasSpace=true;else if(x!='.'&&hasSpace)l2+=QString(x);elsel1+=QString(x);}int s1=l1.toInt(nullptr,10);int s2=l2.toInt(nullptr,10);int max;if(s1>s2)max=s1;elsemax=s2;for(int j=2;j<max;j++){if(s1 % j==0&&s2%j==0){max_yue=j;}}int z=s1*s2/max_yue;QString c_mul=QString::number(z);ui->lineEdit->setText(c_mul);
}void MainWindow::on_pushButton_25_clicked()//公约数,两个数以小数点分格
{QString str=ui->lineEdit->text();QString l1="0",l2="0";QByteArray yue = str.toLatin1();bool hasSpace = false;QString c_div="1";for(int i=0;i<yue.size();i++){char x=yue[i];if(x=='.')hasSpace=true;else if(x!='.'&&hasSpace)l2+=QString(x);elsel1+=QString(x);}int s1=l1.toInt(nullptr,10);int s2=l2.toInt(nullptr,10);int max;if(s1>s2)max=s1;elsemax=s2;for(int j=2;j<max;j++){if(s1 % j==0&&s2%j==0){c_div+="*";c_div+=QString::number(j);}}ui->lineEdit->setText(c_div);
}void MainWindow::on_pushButton_26_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("^"));
}void MainWindow::on_pushButton_27_clicked()
{QString str=ui->lineEdit->text();ui->lineEdit->setText(QString("%1%2").arg(str).arg("log"));
}

3.参数定义

代码如下(示例):


if __name__ == '__main__':parser = argparse.ArgumentParser()parser.add_argument('--weights', nargs='+', type=str, default='yolov5_best_road_crack_recog.pt', help='model.pt path(s)')parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')parser.add_argument('--view-img', action='store_true', help='display results')parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')parser.add_argument('--classes', nargs='+', type=int, default='0', help='filter by class: --class 0, or --class 0 2 3')parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')parser.add_argument('--augment', action='store_true', help='augmented inference')parser.add_argument('--update', action='store_true', help='update all models')parser.add_argument('--project', default='runs/detect', help='save results to project/name')parser.add_argument('--name', default='exp', help='save results to project/name')parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')opt = parser.parse_args()

3.运行结果如下

 

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Qt, C++, Python入门指导
3)界面美化
4)软件制作

 当前文章连接:https://blog.csdn.net/alicema1111/article/details/132608892

博主推荐文章:python人脸识别统计人数qt窗体-CSDN博客

博主推荐文章:Python Yolov5火焰烟雾识别源码分享-CSDN博客

                         Python OpenCV识别行人入口进出人数统计_python识别人数-CSDN博客

个人博客主页:alicema1111的博客_CSDN博客-Python,C++,网页领域博主

博主所有文章点这里alicema1111的博客_CSDN博客-Python,C++,网页领域博主

相关文章:

Qt+C++桌面计算器源码

程序示例精选 QtC桌面计算器源码 如需安装运行环境或远程调试&#xff0c;见文章底部个人QQ名片&#xff0c;由专业技术人员远程协助&#xff01; 前言 这篇博客针对<<QtC桌面计算器源码>>编写代码&#xff0c;代码整洁&#xff0c;规则&#xff0c;易读。 学习与…...

kubesphere安装Maven+JDK17 流水线打包

kubesphere 3.4.0版本&#xff0c;默认支持的jav版本是8和11&#xff0c;不支持17 。需要我们自己定义JenKins Agent 。方法如下&#xff1a; 一、构建镜像 1、我们需要从Jenkins Agent的github仓库拉取master最新源码&#xff0c;最新源码里已经支持jdk17了。 git clone ht…...

百度搜索清理大量低质量网站

我是卢松松&#xff0c;点点上面的头像&#xff0c;欢迎关注我哦&#xff01; 据部分站长爆料&#xff1a;百度大规模删低质量网站的百度资源站长平台权限&#xff0c;很多网站都被删除了百度站长资源平台后台权限&#xff0c;以前在百度后台添加的网站大量被删除&#xff01;…...

WPF数据模板

样式提供了基本的格式化能力&#xff0c;但它们不能消除到目前为止看到的列表的最重要的局限性&#xff1a;不管如何修改ListBoxItem&#xff0c;它都只是ListBoxItem&#xff0c;而不是功能更强大的元素组合。并且因为每个ListBoxItem只支持单个绑定字段&#xff0c;所以不可能…...

浙江绿农环境:将废弃矿山变耕地,为生态文明贡献力量

近年来&#xff0c;随着可持续发展理念在中国乃至全球的日益普及&#xff0c;浙江绿农生态环境有限公司以其独特的创新和实践&#xff0c;成为了绿色发展的典范&#xff0c;在奋进新时代、建设新天堂的背景下&#xff0c;绿农环境在杭州市固废治理行业迈出坚实的步伐&#xff0…...

HTML/CSS盒子模型

盒子&#xff1a;页面中的所有的元素&#xff08;标签&#xff09;&#xff0c;都可以看做一个盒子&#xff0c;由盒子将页面中的元素包含在一个矩形区域内&#xff0c;通过盒子的视角更加方便的进行页面布局 盒子模型的组成&#xff1a; 内容区域&#xff08;content&#xff…...

《Java面向对象程序设计》学习笔记——CSV文件的读写与处理

​笔记汇总&#xff1a;《Java面向对象程序设计》学习笔记 笔记记录的不是非常详实&#xff0c;如果有补充的建议或纠错&#xff0c;请踊跃评论留言&#xff01;&#xff01;&#xff01; 什么是CSV文件 CSV文件的定义 CSV 是英文 comma-separated values 的缩写&#xff0…...

opencv 案例05-基于二值图像分析(简单缺陷检测)

缺陷检测&#xff0c;分为两个部分&#xff0c;一个部分是提取指定的轮廓&#xff0c;第二个部分通过对比实现划痕检测与缺角检测。本次主要搞定第一部分&#xff0c;学会观察图像与提取图像ROI对象轮廓外接矩形与轮廓。 下面是基于二值图像分析的大致流程 读取图像将图像转换…...

Elasticsearch入门介绍

应用场景 1 它提供了强大的搜索功能&#xff0c;可以实现类似百度、谷歌等搜索。 2 可以搜索日志或者交易数据&#xff0c;用来分析商业趋势、搜集日志、分析系统瓶颈或者运行发展等等 3 可以提供预警功能&#xff08;持续的查询分析某个数据&#xff0c;如果超过一定的值&a…...

QML Book 学习基础3(动画)

目录 主要动画元素 例子&#xff1a; 非线性动画 分组动画 Qt 动画是一种在 Qt 框架下创建交互式和引人入胜的图形用户界面的方法&#xff0c;我们可以认为是对某个基础元素的多个设置 主要动画元素 PropertyAnimation-属性值变化时的动画 NumberA…...

Lesson4-3:OpenCV图像特征提取与描述---SIFT/SURF算法

学习目标 理解 S I F T / S U R F SIFT/SURF SIFT/SURF算法的原理&#xff0c;能够使用 S I F T / S U R F SIFT/SURF SIFT/SURF进行关键点的检测 SIFT/SURF算法 1.1 SIFT原理 前面两节我们介绍了 H a r r i s Harris Harris和 S h i − T o m a s i Shi-Tomasi Shi−Tomasi…...

语言基础篇9——Python流程控制

流程控制 顺序结构、条件结构、循环结构&#xff0c;顺序结构由自上而下的语句构成&#xff0c;条件结构由if、match-case构成&#xff0c;循环结构由for、while构成。 if语句 flag 1 if flag 1:print("A") elif flag 2:print("B") else:print("…...

MATLAB算法实战应用案例精讲-【概念篇】构建数据指标方法(补充篇)

目录 前言 几个高频面试题目 指标与标签的区别 几个相关概念 数据域 业务过程...

【pyqt5界面化工具开发-12】QtDesigner图形化界面设计

目录 0x00 前言 一、启动程序 二、基础的使用 三、保存布局文件 四、加载UI文件 0x00 前言 关于QtDesigner工具的配置等步骤&#xff08;网上链接也比较多&#xff09; 下列链接非本人的&#xff08;如果使用pip 在命令行安装过pyqt5以及tools&#xff0c;那么就可以跳过…...

CXL.mem S2M Message 释义

&#x1f525;点击查看精选 CXL 系列文章&#x1f525; &#x1f525;点击进入【芯片设计验证】社区&#xff0c;查看更多精彩内容&#x1f525; &#x1f4e2; 声明&#xff1a; &#x1f96d; 作者主页&#xff1a;【MangoPapa的CSDN主页】。⚠️ 本文首发于CSDN&#xff0c…...

设计模式—外观模式(Facade)

目录 一、什么是外观模式&#xff1f; 二、外观模式具有什么优点吗&#xff1f; 三、外观模式具有什么缺点呢&#xff1f; 四、什么时候使用外观模式&#xff1f; 五、代码展示 ①、股民炒股代码 ②、投资基金代码 ③外观模式 思维导图 一、什么是外观模式&#xff1f;…...

Stack Overflow开发者调查发布:AI将如何协助DevOps

Stack Overflow 发布了开创性的2023年度开发人员调查报告 [1]。报告对 90,000 多名开发人员进行了调查&#xff0c;全面展示了当前软件开发人员的体验。接下来&#xff0c;本文将重点介绍几项重要发现&#xff0c;即重要编程语言和工具偏好、人工智能在开发工作流程中的应用以及…...

去掉鼠标系列之二:Sublime Text快捷键使用指南

系列之二&#xff0c;Sublime Text。 Sublime Text 是我们常用的文本工具&#xff0c;常常要沉浸如其中使用&#xff0c;而不希望被鼠标打扰&#xff0c;所以也记录一下。 学会下面这些快捷键&#xff0c;基本上就不需要移动鼠标啦。 1&#xff0c;CtrlK&#xff0c;CtrlV …...

docker-compose安装node-exporter, prometheus, grafana

基础 exporter提供监控数据 prometheus拉取监控数据 grafana可视化监控数据 准备 全部操作在/root/mypromethus中执行 node_exporter docker-compose -f node-exporter.yaml up -d # web访问&#xff0c;查看node_exporter采集到的数据 http://192.168.1.102:9101/metrics…...

企业架构LNMP学习笔记10

1、Nginx版本&#xff0c;在实际的业务场景中&#xff0c;需要使用软件新版本的功能、特性。就需要对原有软件进行升级或重装系统。 Nginx的版本需要升级迭代。那么如何进行升级呢&#xff1f;线上服务器如何升级&#xff0c;我们选择稳定版本。 从nginx的1.14版本升级到ngin…...

大话软工笔记—需求分析概述

需求分析&#xff0c;就是要对需求调研收集到的资料信息逐个地进行拆分、研究&#xff0c;从大量的不确定“需求”中确定出哪些需求最终要转换为确定的“功能需求”。 需求分析的作用非常重要&#xff0c;后续设计的依据主要来自于需求分析的成果&#xff0c;包括: 项目的目的…...

Golang 面试经典题:map 的 key 可以是什么类型?哪些不可以?

Golang 面试经典题&#xff1a;map 的 key 可以是什么类型&#xff1f;哪些不可以&#xff1f; 在 Golang 的面试中&#xff0c;map 类型的使用是一个常见的考点&#xff0c;其中对 key 类型的合法性 是一道常被提及的基础却很容易被忽视的问题。本文将带你深入理解 Golang 中…...

在rocky linux 9.5上在线安装 docker

前面是指南&#xff0c;后面是日志 sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo dnf install docker-ce docker-ce-cli containerd.io -y docker version sudo systemctl start docker sudo systemctl status docker …...

最新SpringBoot+SpringCloud+Nacos微服务框架分享

文章目录 前言一、服务规划二、架构核心1.cloud的pom2.gateway的异常handler3.gateway的filter4、admin的pom5、admin的登录核心 三、code-helper分享总结 前言 最近有个活蛮赶的&#xff0c;根据Excel列的需求预估的工时直接打骨折&#xff0c;不要问我为什么&#xff0c;主要…...

HTML前端开发:JavaScript 常用事件详解

作为前端开发的核心&#xff0c;JavaScript 事件是用户与网页交互的基础。以下是常见事件的详细说明和用法示例&#xff1a; 1. onclick - 点击事件 当元素被单击时触发&#xff08;左键点击&#xff09; button.onclick function() {alert("按钮被点击了&#xff01;&…...

Fabric V2.5 通用溯源系统——增加图片上传与下载功能

fabric-trace项目在发布一年后,部署量已突破1000次,为支持更多场景,现新增支持图片信息上链,本文对图片上传、下载功能代码进行梳理,包含智能合约、后端、前端部分。 一、智能合约修改 为了增加图片信息上链溯源,需要对底层数据结构进行修改,在此对智能合约中的农产品数…...

代码随想录刷题day30

1、零钱兑换II 给你一个整数数组 coins 表示不同面额的硬币&#xff0c;另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额&#xff0c;返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带…...

使用Spring AI和MCP协议构建图片搜索服务

目录 使用Spring AI和MCP协议构建图片搜索服务 引言 技术栈概览 项目架构设计 架构图 服务端开发 1. 创建Spring Boot项目 2. 实现图片搜索工具 3. 配置传输模式 Stdio模式&#xff08;本地调用&#xff09; SSE模式&#xff08;远程调用&#xff09; 4. 注册工具提…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

Go 并发编程基础:通道(Channel)的使用

在 Go 中&#xff0c;Channel 是 Goroutine 之间通信的核心机制。它提供了一个线程安全的通信方式&#xff0c;用于在多个 Goroutine 之间传递数据&#xff0c;从而实现高效的并发编程。 本章将介绍 Channel 的基本概念、用法、缓冲、关闭机制以及 select 的使用。 一、Channel…...