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

QT study DAY2

作业

代码

Widget.h

class Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();void save_data(const QString& filename,const QString& data);
private slots:void on_lineEdit_textChanged();                //账户栏void on_lineEdit_2_textChanged();              //密码栏void on_radioButton_clicked(bool checked);     //显示密码//新增代码void on_logButton_clicked();        //登录按钮void on_listWidget_itemDoubleClicked(QListWidgetItem *item);    //listWidget双击private:Ui::Widget *ui;QFile file;
};
#endif // WIDGET_H

Widget.cpp

//新增代码//登录按键 点击事件
void Widget::on_logButton_clicked()     
{QString name = ui->lineEdit->text();QList<QListWidgetItem *> res = ui->listWidget->findItems(name,Qt::MatchExactly);if(res.isEmpty()){ui->listWidget->addItem(name);}
}
//listWidget 双击事件
void Widget::on_listWidget_itemDoubleClicked(QListWidgetItem *item) 
{int row = ui->listWidget->row(item);ui->listWidget->takeItem(row);
}

效果

双击之前

双击之后

作业

代码

Widget.h

class Widget : public QWidget
{Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:// 数字按键部分void on_pushButton_0_clicked();void on_pushButton_1_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();void on_pushButton_4_clicked();void on_pushButton_5_clicked();void on_pushButton_6_clicked();void on_pushButton_7_clicked();void on_pushButton_8_clicked();void on_pushButton_9_clicked();// 加减乘除void on_pushButton_add_clicked();void on_pushButton_sub_clicked();void on_pushButton_mul_clicked();void on_pushButton_div_clicked();// 其他按键void on_pushButton_clear_clicked();void on_pushButton_res_clicked();
private:Ui::Widget *ui;QString str;    // 第一个数QString ch;     // 加减乘除QString str2;   // 第二个数QString res;    // 结果int line = 1;   // 标志位
};
#endif

Widget.cpp

Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);
}Widget::~Widget()
{delete ui;
}
/*************** 数字键盘区 ***************/
void Widget::on_pushButton_0_clicked()
{if(line == 1){str+='0';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='0';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_1_clicked()
{if(line == 1){str+='1';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='1';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_2_clicked()
{if(line == 1){str+='2';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='2';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_3_clicked()
{if(line == 1){str+='3';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='3';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_4_clicked()
{if(line == 1){str+='4';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='4';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_5_clicked()
{if(line == 1){str+='5';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='5';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_6_clicked()
{if(line == 1){str+='6';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='6';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_7_clicked()
{if(line == 1){str+='7';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='7';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_8_clicked()
{if(line == 1){str+='8';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='8';ui->mainLineEdit_2->setText(str2);}
}void Widget::on_pushButton_9_clicked()
{if(line == 1){str+='9';ui->mainLineEdit->setText(str);}else if(line == 0){str2+='9';ui->mainLineEdit_2->setText(str2);}
}
/*************** 加减乘除区 ***************/
void Widget::on_pushButton_add_clicked()
{ch = '+';line = 0;ui->label->setText("+");
}void Widget::on_pushButton_sub_clicked()
{ch = '-';line = 0;ui->label->setText("-");
}void Widget::on_pushButton_mul_clicked()
{ch = '*';line = 0;ui->label->setText("*");
}void Widget::on_pushButton_div_clicked()
{ch = '/';line = 0;ui->label->setText("/");
}/*************** 数字键盘区 ***************/
void Widget::on_pushButton_clear_clicked()
{if(line == 1){str.clear();ui->mainLineEdit->setText(str);}else if(line == 0){str2.clear();ui->mainLineEdit_2->setText(str2);}else if(line == 3){str.clear();str2.clear();ui->mainLineEdit->setText("");ui->mainLineEdit_2->setText("");ui->resEdit->setText("");line = 1;}
}
/*************** 数字键盘区 ***************/
void Widget::on_pushButton_res_clicked()
{//QString 转 intint index1 = str.toInt();int index2 = str2.toInt();//加减乘除if(ch == '+'){int int_res = index1 + index2;QString string_res = QString::number(int_res);ui->resEdit->setText(string_res);}else if(ch == '-'){int int_res = index1 - index2;QString string_res = QString::number(int_res);ui->resEdit->setText(string_res);}else if(ch == '*'){int int_res = index1 * index2;QString string_res = QString::number(int_res);ui->resEdit->setText(string_res);}else if(ch == '/'){int int_res = index1 / index2;QString string_res = QString::number(int_res);ui->resEdit->setText(string_res);}//说明计算完毕,再次点击C会清除所有line = 3;
}

效果

加减乘除

C键效果

相关文章:

QT study DAY2

作业 代码 Widget.h class Widget : public QWidget {Q_OBJECTpublic:Widget(QWidget *parent nullptr);~Widget();void save_data(const QString& filename,const QString& data); private slots:void on_lineEdit_textChanged(); //账户栏void on_l…...

QT-自定义参数设计框架软件

QT-自定义参数设计框架软件 Chapter1 QT-自定义参数设计框架软件前言一、演示效果二、使用步骤1.应用进行参数注册2.数据库操作单例对象3.参数操作单例对象 三、下载链接 Chapter2 Qt中管理配置参数&#xff08;QSettings、单例模式&#xff09;1 前言2 QSettings类ini文件写in…...

VUE集成Live2d

VUE集成Live2d 目前基于大模型&#xff0c;可以实现一个桌面的3D动画小人&#xff0c;个人猜测可以简介这个项目进行实现 1-参考网址 试了很多项目&#xff0c;只有这个项目直观的把问题说清楚了 Live2D Vue3技术应用:https://blog.csdn.net/hh1233321/article/details/1406947…...

【CPP面经】科大讯飞 腾讯后端开发面经分享

文章目录 C 面试问题整理基础问题简答1. 内存对齐2. this 指针3. 在成员函数中删除 this4. 引用占用内存吗&#xff1f;5. C 越界访问场景6. 进程通信方式7. 无锁队列实现8. ping 在哪一层&#xff1f;实现原理&#xff1f;9. HTTPS 流程10. GDB 使用及 CPU 高使用定位11. 智能…...

el-card 结合 el-descriptions 作为信息展示

记录下el-card 组合 el-descriptions 实现动态展示信息 文章结构 实现效果1. el-descriptions 组件使用1.1 结合v-for实现列表渲染1.2 解析 2. 自定义 el-descriptions 样式2.1 修改背景色、字体颜色2.2 调整字体大小2.3 解析 3. el-card 结合 el-descriptions 作为信息展示3.…...

GaussDB自带诊断工具实战指南

一、引言 GaussDB是一种分布式的关系型数据库。在数据库运维中&#xff0c;快速定位性能瓶颈、诊断故障是保障业务连续性的关键。GaussDB内置了多种诊断工具&#xff0c;结合日志分析、执行计划解析和实时监控功能&#xff0c;帮助开发者与运维人员高效解决问题。本文深入讲解…...

LeetCode 链表章节

简单 21. 合并两个有序链表 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1&#xff1a; 输入&#xff1a;l1 [1,2,4], l2 [1,3,4] 输出&#xff1a;[1,1,2,3,4,4]示例 2&#xff1a; 输入&#xff1a;l1 [], l2…...

SSL证书和HTTPS:全面解析它们的功能与重要性

每当我们在互联网上输入个人信息、进行在线交易时&#xff0c;背后是否有一个安全的保障&#xff1f;这时&#xff0c;SSL证书和HTTPS便扮演了至关重要的角色。本文将全面分析SSL证书和HTTPS的含义、功能、重要性以及它们在网络安全中的作用。 一、SSL证书的定义与基本概念 S…...

正交投影与内积空间:机器学习的几何基础

前言 本文隶属于专栏《机器学习数学通关指南》&#xff0c;该专栏为笔者原创&#xff0c;引用请注明来源&#xff0c;不足和错误之处请在评论区帮忙指出&#xff0c;谢谢&#xff01; 本专栏目录结构和参考文献请见《机器学习数学通关指南》 正文 &#x1f50d; 1. 内积空间的…...

Qt中txt文件输出为PDF格式

main.cpp PdfReportGenerator pdfReportGenerator;// 加载中文字体if (QFontDatabase::addApplicationFont(":/new/prefix1/simsun.ttf") -1) {QMessageBox::warning(nullptr, "警告", "无法加载中文字体");}// 解析日志文件QVector<LogEntr…...

《HelloGitHub》第 107 期

兴趣是最好的老师&#xff0c;HelloGitHub 让你对编程感兴趣&#xff01; 简介 HelloGitHub 分享 GitHub 上有趣、入门级的开源项目。 github.com/521xueweihan/HelloGitHub 这里有实战项目、入门教程、黑科技、开源书籍、大厂开源项目等&#xff0c;涵盖多种编程语言 Python、…...

Langchain解锁LLM大语言模型的结构化输出能力(多种实现方案)

在 LangChain解锁LLM大语言模型的结构化输出能力&#xff1a;调用 with_structured_output() 方法 这篇博客中&#xff0c;我们了解了格式化LLM输出内容的必要性以及如何通过调用langchain框架中提供的 with_structured_output() 方法对LLM输出进行格式化&#xff08;三种可选方…...

AI数据分析:deepseek生成SQL

在当今数据驱动的时代&#xff0c;数据分析已成为企业和个人决策的重要工具。随着人工智能技术的快速发展&#xff0c;AI 驱动的数据分析工具正在改变我们处理和分析数据的方式。本文将着重介绍如何使用 DeepSeek 进行自动补全SQL 查询语句。 我们都知道&#xff0c;SQL 查询语…...

力扣-动态规划-115 不同子序列

思路 dp数组定义&#xff1a;0_i-1的字符串中有0_j-1的字符串有dp[i][j]个递推公式&#xff1a; if(s[i-1] t[j-1]){dp[i][j] dp[i-1][j-1] dp[i-1][j]; }else{dp[i][j] dp[i-1][j]; } 在该元素相同时&#xff0c;有两种可能1&#xff1a;使用该元素&#xff0c;所以0_i-2…...

Qt C++ 开发 动态上下页按钮实现

项目开发&#xff0c;想实现动态的显示按钮&#xff0c;考虑使用QStackedWidget做两个页面去切换。 首先&#xff0c;我们使用Qt ui 画出两个QStackedWidget的两个页面 要实现切换&#xff0c;我们只需要调用stackedWidget->setCurrentIndex(index)就行。 那么如何自动调…...

数据结构第五节:排序

1.常见的排序算法 插入排序&#xff1a;直接插入排序、希尔排序 选择排序&#xff1a;直接选择排序、堆排序 交换排序&#xff1a;冒泡排序、快速排序 归并排序&#xff1a;归并排序 排序的接口实现&#xff1a; // 1. 直接插入排序 void InsertSort(int* a, int n); // 2. 希…...

从文件到块: 提高 Hugging Face 存储效率

Hugging Face 在Git LFS 仓库中存储了超过30 PB 的模型、数据集和 Spaces。由于 Git 在文件级别进行存储和版本控制&#xff0c;任何文件的修改都需要重新上传整个文件。这在 Hub 上会产生高昂的成本&#xff0c;因为平均每个 Parquet 和 CSV 文件大小在 200-300 MB 之间&#…...

Android14 串口控制是能wifi adb实现简介

Android14 串口控制是能wifi adb实现简介 一、前言 文章目录 Android14 串口控制是能wifi adb实现简介一、前言二、Android14 串口控制是能wifi adb实现1、设置prop属性命令开启adb&#xff08;1&#xff09;相关prop属性设置&#xff08;2&#xff09;在设置界面或者 ifconfi…...

vue3中 组合式~测试深入组件:事件 与 $emit()

一、语法(props) 第一步&#xff1a;在组件模板表达式中&#xff0c;可以直接用$emit()方法触发自定义事件&#xff0c; <!-- MyComponent --> <button click"$emit(someEvent)">Click Me</button> 第二步父组件可以通过 v-on (缩写为 ) 来监听…...

SQL-labs13-16闯关记录

http://127.0.0.1/sqli-labs/less-13/ 基于POST单引号双注入变形 1&#xff0c;依然是一个登录框&#xff0c;POST型SQL注入 2&#xff0c;挂上burpsuite&#xff0c;然后抓取请求&#xff0c;构造请求判断漏洞类型和闭合条件 admin 发生了报错&#xff0c;根据提示闭合方式是(…...

Xshell远程连接Kali(默认 | 私钥)Note版

前言:xshell远程连接&#xff0c;私钥连接和常规默认连接 任务一 开启ssh服务 service ssh status //查看ssh服务状态 service ssh start //开启ssh服务 update-rc.d ssh enable //开启自启动ssh服务 任务二 修改配置文件 vi /etc/ssh/ssh_config //第一…...

智慧工地云平台源码,基于微服务架构+Java+Spring Cloud +UniApp +MySql

智慧工地管理云平台系统&#xff0c;智慧工地全套源码&#xff0c;java版智慧工地源码&#xff0c;支持PC端、大屏端、移动端。 智慧工地聚焦建筑行业的市场需求&#xff0c;提供“平台网络终端”的整体解决方案&#xff0c;提供劳务管理、视频管理、智能监测、绿色施工、安全管…...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

django filter 统计数量 按属性去重

在Django中&#xff0c;如果你想要根据某个属性对查询集进行去重并统计数量&#xff0c;你可以使用values()方法配合annotate()方法来实现。这里有两种常见的方法来完成这个需求&#xff1a; 方法1&#xff1a;使用annotate()和Count 假设你有一个模型Item&#xff0c;并且你想…...

Cinnamon修改面板小工具图标

Cinnamon开始菜单-CSDN博客 设置模块都是做好的&#xff0c;比GNOME简单得多&#xff01; 在 applet.js 里增加 const Settings imports.ui.settings;this.settings new Settings.AppletSettings(this, HTYMenusonichy, instance_id); this.settings.bind(menu-icon, menu…...

leetcodeSQL解题:3564. 季节性销售分析

leetcodeSQL解题&#xff1a;3564. 季节性销售分析 题目&#xff1a; 表&#xff1a;sales ---------------------- | Column Name | Type | ---------------------- | sale_id | int | | product_id | int | | sale_date | date | | quantity | int | | price | decimal | -…...

鱼香ros docker配置镜像报错:https://registry-1.docker.io/v2/

使用鱼香ros一件安装docker时的https://registry-1.docker.io/v2/问题 一键安装指令 wget http://fishros.com/install -O fishros && . fishros出现问题&#xff1a;docker pull 失败 网络不同&#xff0c;需要使用镜像源 按照如下步骤操作 sudo vi /etc/docker/dae…...

自然语言处理——循环神经网络

自然语言处理——循环神经网络 循环神经网络应用到基于机器学习的自然语言处理任务序列到类别同步的序列到序列模式异步的序列到序列模式 参数学习和长程依赖问题基于门控的循环神经网络门控循环单元&#xff08;GRU&#xff09;长短期记忆神经网络&#xff08;LSTM&#xff09…...

安卓基础(aar)

重新设置java21的环境&#xff0c;临时设置 $env:JAVA_HOME "D:\Android Studio\jbr" 查看当前环境变量 JAVA_HOME 的值 echo $env:JAVA_HOME 构建ARR文件 ./gradlew :private-lib:assembleRelease 目录是这样的&#xff1a; MyApp/ ├── app/ …...

回溯算法学习

一、电话号码的字母组合 import java.util.ArrayList; import java.util.List;import javax.management.loading.PrivateClassLoader;public class letterCombinations {private static final String[] KEYPAD {"", //0"", //1"abc", //2"…...