QT day5
数据库完成登入注册
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QDebug>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
#include <QMainWindow>
#include<QMessageBox>//消息对话框 //输出函数对应的头文件
#include <QIcon>
#include"form.h"
/*******数据库***********/
#include<QSqlDatabase>//数据库
#include<QSqlRecord>
#include<QMessageBox>
#include<QSqlQuery>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTsignals:void jump();//自定义跳转信号函数void jump2();//自定义跳转信号函数
private slots:void on_btn1_clicked();void on_btn2_clicked();void on_btn3_clicked();public:MainWindow(QWidget *parent = nullptr);~MainWindow();private:Ui::MainWindow *ui;QPushButton *btn1;QPushButton *btn2;QPushButton *btn3;QLineEdit *edit1;QLineEdit *edit2;QSqlDatabase mydb;//数据库
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);this->setFixedSize(600,400);//设置固定尺寸this->setWindowIcon(QIcon(":/new/prefix1/tuku/yh.png"));//改变左上角图标的位this->setWindowTitle("易碗浆糊");//窗口的名字//this->setStyleSheet("background-color:pink;");//背景颜色QLabel *lab1=new QLabel(this);//实例化一个标签lab1->resize(600,170);//重新设置尺寸lab1->setStyleSheet("background-color:yellow");lab1->setAlignment(Qt::AlignCenter);lab1->setPixmap(QPixmap(":/new/prefix1/tuku/fjh.png"));lab1->setScaledContents(true);this->setStyleSheet("background-color:white;");//背景颜色//用户名框edit1=new QLineEdit(this);edit1->resize(230,45);edit1->move(lab1->x()+200,lab1->y()+200);edit1->setPlaceholderText("用户名");//设置占位文本//密码框edit2=new QLineEdit(this);edit2->resize(230,45);edit2->move(edit1->x(),edit1->y()+75);edit2->setPlaceholderText("密码");//设置占位文本edit2->setEchoMode(QLineEdit::Password);//设置回显模式//实例化一个标签QLabel *lab2=new QLabel(this);lab2->resize(45,45);//重新设置尺寸lab2->setAlignment(Qt::AlignCenter);lab2->setPixmap(QPixmap(":/new/prefix1/tuku/wxn.png"));lab2->setScaledContents(true);lab2->move(lab1->x()+140,lab1->y()+200);//实例化一个标签QLabel *lab3=new QLabel(this);lab3->resize(45,45);//重新设置尺寸lab3->setAlignment(Qt::AlignCenter);lab3->setPixmap(QPixmap(":/new/prefix1/tuku/wxnnn.png"));lab3->setScaledContents(true);lab3->move(lab1->x()+140,lab1->y()+275);//实例化一个按钮//QPushButton *btn1=new QPushButton(this);this->btn1=new QPushButton("btn1",this);btn1->setText("登录");btn1->resize(70,40);btn1->move(lab3->x()+80,lab3->y()+70);btn1->setIcon(QIcon(":/new/prefix1/tuku/wq.png"));connect(btn1,&QPushButton::clicked,this,&MainWindow::on_btn1_clicked);// btn1->setStyleSheet("background-color:white;border-radius:10px;");//设置组件背景色//实例化一个按钮// QPushButton *btn2=new QPushButton(this);this->btn2=new QPushButton("btn2",this);btn2->setText("取消");btn2->resize(70,40);btn2->move(btn1->x()+130,btn1->y());// btn2->setStyleSheet("background-color:white;border-radius:10px;");//设置组件背景色btn2->setIcon(QIcon(":/new/prefix1/tuku/wq2.png"));connect(btn2,&QPushButton::clicked,this,&MainWindow::on_btn2_clicked);//实例化一个按钮this->btn3=new QPushButton("btn2",this);btn3->setText("注册");btn3->resize(70,45);btn3->move(edit1->x()+235,edit1->y());connect(btn3,&QPushButton::clicked,this,&MainWindow::on_btn3_clicked);/************************************************/if(!mydb.contains("mydatabase.db")){mydb=QSqlDatabase::addDatabase("QSQLITE");//设置数据库的名字mydb.setDatabaseName("mydatabase.db");}if(!mydb.open()){QMessageBox::information(this,"失败","数据库打开失败");return;}//准备sql语句QString sql="create table if not exists user_info(""name varchar(10),"//用户名"mm integer)";//密码}
void MainWindow::on_btn1_clicked()
{//准备sql语句QString sql="select *from user_info";//准备语句执行者QSqlQuery querry;//执行sql语句if(!querry.exec(sql)){QMessageBox::information(this,"提示","执行失败");return;}int flg=0;QSqlRecord rec = querry.record();//总行while(querry.next()){for(int i=0;i<rec.count();i++){ if(edit1->text()==querry.record().value(0).toString() &&edit2->text()==querry.record().value(1).toString()){flg=1;break;}}}if(flg==1)//登入成功{emit jump();this->hide();}else if(flg==0)//数据库没有相应的密码和用户{QMessageBox box(QMessageBox::Critical,"密码错误","账号密码不匹配,是否重新登录",QMessageBox::Yes|QMessageBox::No,this);box.setButtonText(QMessageBox::Yes,"OK");box.setButtonText(QMessageBox::No,"cancel");int ret=box.exec();if(ret==QMessageBox::Yes){edit1->clear();//清空edit2->clear();//清空}else if(ret==QMessageBox::No){this->close();}}if(edit1->text()=="admin" &&edit2->text()=="12345"){emit jump();this->hide();}}
void MainWindow::on_btn2_clicked()
{int ret1= QMessageBox::question(this,"问题","是否确定要退出登录",QMessageBox::Yes|QMessageBox::No,QMessageBox::No);//对用户选中的按钮进行判断if(ret1==QMessageBox::Yes){this->close();}else if(ret1==QMessageBox::No){edit1->clear();//清空edit2->clear();//清空}}//注册按钮的槽函数
void MainWindow::on_btn3_clicked()
{emit jump2();this->hide();
}MainWindow::~MainWindow()
{delete ui;
}
from.h
#ifndef FORM_H
#define FORM_H
#include<QMessageBox>//消息对话框
#include <QMainWindow>
#include <QWidget>
namespace Ui {
class Form;
}class Form : public QWidget
{Q_OBJECTpublic slots:void jump_slot();void on_bt3_clicked();
public:explicit Form(QWidget *parent = nullptr);~Form();private:Ui::Form *ui;};#endif // FORM_H
form.cpp
#include "form.h"
#include "ui_form.h"Form::Form(QWidget *parent) :QWidget(parent),ui(new Ui::Form)
{ui->setupUi(this);this->setWindowIcon(QIcon(":/new/prefix1/tuku/yh.png"));//改变左上角图标的位this->setWindowTitle("成功");//窗口的名字}Form::~Form()
{delete ui;
}
//跳转
void Form::jump_slot()
{this->show();}void Form::on_bt3_clicked()
{close();
}
zcfrom.h
#ifndef ZCFROM_H
#define ZCFROM_H
#include<QMessageBox>//消息对话框
#include <QMainWindow>
#include <QWidget>
#include <QMainWindow>
#include<QDebug>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
#include <QMainWindow>
#include<QMessageBox>//消息对话框 //输出函数对应的头文件
#include <QIcon>
#include"form.h"
/*******数据库***********/
#include<QSqlDatabase>//数据库
#include<QSqlRecord>
#include<QMessageBox>
#include<QSqlQuery>
namespace Ui {
class zcfrom;
}class zcfrom : public QWidget
{Q_OBJECT
signals:void jump3();//自定义跳转信号函数
public slots:void jump2_slot();
public:explicit zcfrom(QWidget *parent = nullptr);~zcfrom();private slots:void on_zcBttn_clicked();void on_fhbttn_clicked();private:Ui::zcfrom *ui;QSqlDatabase mydb;//数据库
};#endif // ZCFROM_H
zcfrom.cpp
#include "zcfrom.h"
#include "ui_zcfrom.h"zcfrom::zcfrom(QWidget *parent) :QWidget(parent),ui(new Ui::zcfrom)
{ui->setupUi(this);this->setWindowTitle("注册");//窗口的名字this->setWindowIcon(QIcon(":/new/prefix1/tuku/yh.png"));//改变左上角图标的位if(!mydb.contains("mydatabase.db")){mydb=QSqlDatabase::addDatabase("QSQLITE");//设置数据库的名字mydb.setDatabaseName("mydatabase.db");}if(!mydb.open()){QMessageBox::information(this,"失败","数据库打开失败");return;}//准备sql语句QString sql="create table if not exists user_info(""name varchar(10),"//用户名"mm integer)";//密码//准备语句执行者QSqlQuery querry;//让语句执行者指向sql语句//成功true失败falseif(!querry.exec(sql)){QMessageBox::information(this,"失败","失败");return;}
}zcfrom::~zcfrom()
{delete ui;
}
void zcfrom::jump2_slot()
{this->show();}
//确定
void zcfrom::on_zcBttn_clicked()
{QString name=ui->nameEdit->text();int mm=ui->mmEdit->text().toInt();if(name.isEmpty()||mm==0){QMessageBox::information(this,"提示","数据未填写完整");return;}//准备sql语句QString sql=QString("insert into user_info(name,mm)""values('%1',%4)").arg(name).arg(mm);QSqlQuery querry;if(!querry.exec(sql)){QMessageBox::information(this,"失败","注册失败");return;}else{ui->nameEdit->clear();ui->mmEdit->clear();QMessageBox::information(this,"成功","注册成功");//此界面消失emit jump3();this->hide();}
}
//返回登录按钮的槽函数void zcfrom::on_fhbttn_clicked()
{emit jump3();this->hide();
}
main.cpp
#include "mainwindow.h"
#include "form.h"
#include <QApplication>
#include "zcfrom.h"
int main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();Form s;//定义第二个界面QObject::connect(&w,&MainWindow::jump,&s,&Form::jump_slot);zcfrom s2;//定义第二个界面QObject::connect(&w,&MainWindow::jump2,&s2,&zcfrom::jump2_slot);QObject::connect(&s2,&zcfrom::jump3,&w,&MainWindow::show);//定义第二个界面return a.exec();
}
03dljm.pro
QT += core gui sqlgreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++11# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \form.cpp \main.cpp \mainwindow.cpp \zcfrom.cppHEADERS += \form.h \mainwindow.h \zcfrom.hFORMS += \form.ui \mainwindow.ui \zcfrom.ui# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetRESOURCES += \ttp.qrcINCLUDEPATH += D:/opencv/opencv3.4-qt-intall/install/include
INCLUDEPATH += D:/opencv/opencv3.4-qt-intall/install/include/opencv
INCLUDEPATH += D:/opencv/opencv3.4-qt-intall/install/include/opencv2
LIBS += D:/opencv/opencv3.4-qt-intall/install/x86/mingw/lib/libopencv_*.a
智能指针思维导图
相关文章:

QT day5
数据库完成登入注册 mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<QDebug> #include<QPushButton> #include<QLineEdit> #include<QLabel> #include <QMainWindow> #include<QMessageBo…...

设计模式Java实战
文章目录 一、前置1.1 目的1.2 面向对象1.3 接口和抽象类 二、七大设计原则2.1 单一职责2.2 接口隔离原则2.3 依赖倒转原则2.4 里氏替换原则2.5 开闭原则2.6 不要重复原则2.7 迪米特最少知道法则 三、23种设计模式3.1创建型:创建对象3.1.1 单例模式定义最佳实践场景…...

外国固定资产管理系统功能有哪些
很多公司都在寻找提高自己资产管理效益的方法。为了满足这一要求,国外的固定资产管理系统已经发展成多种形式。以下是国外一些常见的固定资产管理系统的特点:自动化和智能化:许多现代固定资产管理系统采用自动化和数字化技术,以简化流程,减少…...

Postman应用——控制台调试
当你在测试脚本中遇到错误或意外行为时,Postman控制台可以帮助你识别,通过将console.log调试语句与你的测试断言相结合,你可以检查http请求和响应的内容,以及变量之类的。 通常可以使用控制台日志来标记代码执行,有时…...

如何制作思维导图?
思维导图是一种非常有用的工具,可以被广泛应用于不同领域的人群。以下是一些常见的使用人群:学生、教育工作人员、各领域的专业人员,法律、商业、医学等等,创作者、艺术家、个人自我成长管理。 由此可见,思维导图可以做…...

【力扣每日一题】2023.9.21 收集树中金币
目录 题目: 示例: 分析: 代码: 题目: 示例: 分析: 题目给我们一棵树,不过这棵树不是普通的树,而是无向无根树。给我们一个二维数组表示节点之间的连接关系ÿ…...

Python与数据分析--每天绘制Matplotlib库实例图片3张-第1天
目录 1.实例1--Bar color demo 2.实例2--Bar Label Demo 3.实例3--Grouped bar chart with labels 1.实例1--Bar color demo import matplotlib.pyplot as plt # 支持中文 plt.rcParams[font.sans-serif] [SimHei] # 用来正常显示中文标签 plt.rcParams[axes.unicode_minus…...

pycharm 中package, directory, sources root, resources root的区别
【遇到的问题】 导入yolov5中有utils文件,自己的代码中也有utils文件,使得yolov5中的这部分引用出错了。 【解决方案】 单独建立detection文件夹,把检测相关的都放在这里,yolov5是github上拉取的源码,发现yolov5中fr…...

【谢希尔 计算机网络】第2章 物理层
目录 通信基础 基本概念 两个公式lim 奈氏准则 香农定理 奈氏准则 VS 香农定理 编码与调制 编辑 物理层下面的传输媒体 导引型传输媒体 1. 双绞线 2. 同轴电缆 3. 光缆 非导引型传输媒体 无线电微波通信 卫星通信 无线局域网使用的 ISM 频段 信道复用技术 …...
Eclipse工具使用技巧
1、常用快捷键 ctrlshifto 快速导包 CtrlSpace 内容助理 说明:内容助理。提供对方法,变量,参数,javadoc等得提示,应运在多种场合,总之需要提示的时候可先按此快捷键。注:避免输入法的切换设置与此设置冲突 CtrlShiftSpace 变量提示 Ctrl/ 添加/消除//注释 CtrlShift/ 添加…...
python LeetCode 刷题记录 94
题目 给定一个二叉树的根节点 root ,返回 它的 中序 遍历 代码 递归 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val0, leftNone, rightNone): # self.val val # self.left left # self.righ…...

滴滴可观测平台 Metrics 指标实时计算如何实现了又准又省?
在滴滴,可观测平台的 Metrics 数据有一些实时计算的需求,承载这些实时计算需求的是一套又一套的 Flink 任务。之所以会有多套 Flink 任务,是因为每个服务按照其业务观测需要不同的指标计算,也就对应了不同数据处理拓扑。我们尽力抽…...

每天几道Java面试题:IO流(第五天)
目录 第五幕 、第一场)街边 友情提醒 背面试题很枯燥,加入一些戏剧场景故事人物来加深记忆。PS:点击文章目录可直接跳转到文章指定位置。 第五幕 、 第一场)街边 【衣衫褴褛老者,保洁阿姨,面试者老王】 衣衫褴褛老…...
js/axios/umi-request 根据后端返回的二进制流下载文件
type ResponseType {data: Blob;headers: {content-disposition?: string;}; }; // 下载 (创建a标签) export const downloadBlob (response: ResponseType) > {const blob response.data; // 获取响应中的 Blob 数据const contentDisposition response.headers[conten…...
软件评测师之流水线
目录 一.概念二.周期三.执行时间的计算 一.概念 程序在执行时多条指令可以层叠并行的技术。 二.周期 取指→分析→执行 指令执行的各个阶段里面,执行时间最长的为流水线的周期。 三.执行时间的计算 n条指令执行的总时间流水线计算公式:单条指令所需…...

Linux系统编程——网络编程的学习
Linux系统编程学习相关博文 Linux系统编程——文件编程的学习Linux系统编程——进程的学习Linux系统编程——进程间通信的学习Linux系统编程——线程的学习 Linux系统编程——网络编程的学习 一、概述1. TCP/UDP2. 端口号3. 字节序4. Sockt服务器和客户端的开发步骤1. 服务器2…...
Vue中的ref 和$refs的使用
ref 和$refs 作用:利用ref 和$refs可以用于获取dom元素,或组件实例 特点:查找范围→当前组件内(更精确稳定,原生的dom在vue子组件中查找最终也会扫描到父组件) 1. 获取dom 目标标签–添加ref 属性 <…...
Hive【非交互式使用、三种参数配置方式】
前言 今天开始学习 Hive,因为毕竟但凡做个项目基本就避不开用 Hive ,争取这学期结束前做个小点的项目。 第一篇博客内容还是比较少的,环境的搭建配置太琐碎没有写。 Hive 常用使用技巧 交互式使用 就是我们正常的进入 hive 命令行下的使用…...
基于Yolov8的工业小目标缺陷检测(1)
目录 1.工业油污数据集介绍 1.1 小目标定义 1.2 难点 1.3 工业缺陷检测算法介绍 1.3.1 YOLOv8...
Python文件操作和管理指南:打开、读取、写入和管理文件
文章目录 文件(File)打开文件使用 with ... as 语句打开文件读取文件内容读取大文件的方式逐行读取和读取全部行写文件操作文件定位seek()tell() 关闭文件 文件管理获取目录结构获取当前目录切换当前所在目录创建目录删除目录删除文件重命名文件 总结pyt…...

Docker 离线安装指南
参考文章 1、确认操作系统类型及内核版本 Docker依赖于Linux内核的一些特性,不同版本的Docker对内核版本有不同要求。例如,Docker 17.06及之后的版本通常需要Linux内核3.10及以上版本,Docker17.09及更高版本对应Linux内核4.9.x及更高版本。…...
【Java学习笔记】Arrays类
Arrays 类 1. 导入包:import java.util.Arrays 2. 常用方法一览表 方法描述Arrays.toString()返回数组的字符串形式Arrays.sort()排序(自然排序和定制排序)Arrays.binarySearch()通过二分搜索法进行查找(前提:数组是…...
Axios请求超时重发机制
Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式: 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...
大模型多显卡多服务器并行计算方法与实践指南
一、分布式训练概述 大规模语言模型的训练通常需要分布式计算技术,以解决单机资源不足的问题。分布式训练主要分为两种模式: 数据并行:将数据分片到不同设备,每个设备拥有完整的模型副本 模型并行:将模型分割到不同设备,每个设备处理部分模型计算 现代大模型训练通常结合…...

算法笔记2
1.字符串拼接最好用StringBuilder,不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...
重启Eureka集群中的节点,对已经注册的服务有什么影响
先看答案,如果正确地操作,重启Eureka集群中的节点,对已经注册的服务影响非常小,甚至可以做到无感知。 但如果操作不当,可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...
【生成模型】视频生成论文调研
工作清单 上游应用方向:控制、速度、时长、高动态、多主体驱动 类型工作基础模型WAN / WAN-VACE / HunyuanVideo控制条件轨迹控制ATI~镜头控制ReCamMaster~多主体驱动Phantom~音频驱动Let Them Talk: Audio-Driven Multi-Person Conversational Video Generation速…...

【网络安全】开源系统getshell漏洞挖掘
审计过程: 在入口文件admin/index.php中: 用户可以通过m,c,a等参数控制加载的文件和方法,在app/system/entrance.php中存在重点代码: 当M_TYPE system并且M_MODULE include时,会设置常量PATH_OWN_FILE为PATH_APP.M_T…...
Kafka主题运维全指南:从基础配置到故障处理
#作者:张桐瑞 文章目录 主题日常管理1. 修改主题分区。2. 修改主题级别参数。3. 变更副本数。4. 修改主题限速。5.主题分区迁移。6. 常见主题错误处理常见错误1:主题删除失败。常见错误2:__consumer_offsets占用太多的磁盘。 主题日常管理 …...
MySQL 主从同步异常处理
阅读原文:https://www.xiaozaoshu.top/articles/mysql-m-s-update-pk MySQL 做双主,遇到的这个错误: Could not execute Update_rows event on table ... Error_code: 1032是 MySQL 主从复制时的经典错误之一,通常表示ÿ…...