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

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创建型&#xff1a;创建对象3.1.1 单例模式定义最佳实践场景…...

外国固定资产管理系统功能有哪些

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

Postman应用——控制台调试

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

如何制作思维导图?

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

【力扣每日一题】2023.9.21 收集树中金币

目录 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 代码&#xff1a; 题目&#xff1a; 示例&#xff1a; 分析&#xff1a; 题目给我们一棵树&#xff0c;不过这棵树不是普通的树&#xff0c;而是无向无根树。给我们一个二维数组表示节点之间的连接关系&#xff…...

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文件&#xff0c;自己的代码中也有utils文件&#xff0c;使得yolov5中的这部分引用出错了。 【解决方案】 单独建立detection文件夹&#xff0c;把检测相关的都放在这里&#xff0c;yolov5是github上拉取的源码&#xff0c;发现yolov5中fr…...

【谢希尔 计算机网络】第2章 物理层

目录 通信基础 基本概念 两个公式lim 奈氏准则 香农定理 奈氏准则 VS 香农定理 编码与调制 ​编辑 物理层下面的传输媒体 导引型传输媒体 1. 双绞线 2. 同轴电缆 3. 光缆 非导引型传输媒体 无线电微波通信 卫星通信 无线局域网使用的 ISM 频段 信道复用技术 …...

Eclipse工具使用技巧

1、常用快捷键 ctrlshifto 快速导包 CtrlSpace 内容助理 说明:内容助理。提供对方法,变量,参数,javadoc等得提示,应运在多种场合,总之需要提示的时候可先按此快捷键。注:避免输入法的切换设置与此设置冲突 CtrlShiftSpace 变量提示 Ctrl/ 添加/消除//注释 CtrlShift/ 添加…...

python LeetCode 刷题记录 94

题目 给定一个二叉树的根节点 root &#xff0c;返回 它的 中序 遍历 代码 递归 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val0, leftNone, rightNone): # self.val val # self.left left # self.righ…...

滴滴可观测平台 Metrics 指标实时计算如何实现了又准又省?

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

每天几道Java面试题:IO流(第五天)

目录 第五幕 、第一场&#xff09;街边 友情提醒 背面试题很枯燥&#xff0c;加入一些戏剧场景故事人物来加深记忆。PS:点击文章目录可直接跳转到文章指定位置。 第五幕 、 第一场&#xff09;街边 【衣衫褴褛老者&#xff0c;保洁阿姨&#xff0c;面试者老王】 衣衫褴褛老…...

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…...

软件评测师之流水线

目录 一.概念二.周期三.执行时间的计算 一.概念 程序在执行时多条指令可以层叠并行的技术。 二.周期 取指→分析→执行 指令执行的各个阶段里面&#xff0c;执行时间最长的为流水线的周期。 三.执行时间的计算 n条指令执行的总时间流水线计算公式&#xff1a;单条指令所需…...

Linux系统编程——网络编程的学习

Linux系统编程学习相关博文 Linux系统编程——文件编程的学习Linux系统编程——进程的学习Linux系统编程——进程间通信的学习Linux系统编程——线程的学习 Linux系统编程——网络编程的学习 一、概述1. TCP/UDP2. 端口号3. 字节序4. Sockt服务器和客户端的开发步骤1. 服务器2…...

Vue中的ref 和$refs的使用

ref 和$refs 作用&#xff1a;利用ref 和$refs可以用于获取dom元素&#xff0c;或组件实例 特点&#xff1a;查找范围→当前组件内&#xff08;更精确稳定&#xff0c;原生的dom在vue子组件中查找最终也会扫描到父组件&#xff09; 1. 获取dom 目标标签–添加ref 属性 <…...

Hive【非交互式使用、三种参数配置方式】

前言 今天开始学习 Hive&#xff0c;因为毕竟但凡做个项目基本就避不开用 Hive &#xff0c;争取这学期结束前做个小点的项目。 第一篇博客内容还是比较少的&#xff0c;环境的搭建配置太琐碎没有写。 Hive 常用使用技巧 交互式使用 就是我们正常的进入 hive 命令行下的使用…...

基于Yolov8的工业小目标缺陷检测(1)

目录 1.工业油污数据集介绍 1.1 小目标定义 1.2 难点 1.3 工业缺陷检测算法介绍 1.3.1 YOLOv8...

Python文件操作和管理指南:打开、读取、写入和管理文件

文章目录 文件&#xff08;File&#xff09;打开文件使用 with ... as 语句打开文件读取文件内容读取大文件的方式逐行读取和读取全部行写文件操作文件定位seek()tell() 关闭文件 文件管理获取目录结构获取当前目录切换当前所在目录创建目录删除目录删除文件重命名文件 总结pyt…...

java_网络服务相关_gateway_nacos_feign区别联系

1. spring-cloud-starter-gateway 作用&#xff1a;作为微服务架构的网关&#xff0c;统一入口&#xff0c;处理所有外部请求。 核心能力&#xff1a; 路由转发&#xff08;基于路径、服务名等&#xff09;过滤器&#xff08;鉴权、限流、日志、Header 处理&#xff09;支持负…...

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 //第一…...

聊聊 Pulsar:Producer 源码解析

一、前言 Apache Pulsar 是一个企业级的开源分布式消息传递平台&#xff0c;以其高性能、可扩展性和存储计算分离架构在消息队列和流处理领域独树一帜。在 Pulsar 的核心架构中&#xff0c;Producer&#xff08;生产者&#xff09; 是连接客户端应用与消息队列的第一步。生产者…...

条件运算符

C中的三目运算符&#xff08;也称条件运算符&#xff0c;英文&#xff1a;ternary operator&#xff09;是一种简洁的条件选择语句&#xff0c;语法如下&#xff1a; 条件表达式 ? 表达式1 : 表达式2• 如果“条件表达式”为true&#xff0c;则整个表达式的结果为“表达式1”…...

定时器任务——若依源码分析

分析util包下面的工具类schedule utils&#xff1a; ScheduleUtils 是若依中用于与 Quartz 框架交互的工具类&#xff0c;封装了定时任务的 创建、更新、暂停、删除等核心逻辑。 createScheduleJob createScheduleJob 用于将任务注册到 Quartz&#xff0c;先构建任务的 JobD…...

在Ubuntu中设置开机自动运行(sudo)指令的指南

在Ubuntu系统中&#xff0c;有时需要在系统启动时自动执行某些命令&#xff0c;特别是需要 sudo权限的指令。为了实现这一功能&#xff0c;可以使用多种方法&#xff0c;包括编写Systemd服务、配置 rc.local文件或使用 cron任务计划。本文将详细介绍这些方法&#xff0c;并提供…...

DBAPI如何优雅的获取单条数据

API如何优雅的获取单条数据 案例一 对于查询类API&#xff0c;查询的是单条数据&#xff0c;比如根据主键ID查询用户信息&#xff0c;sql如下&#xff1a; select id, name, age from user where id #{id}API默认返回的数据格式是多条的&#xff0c;如下&#xff1a; {&qu…...

3403. 从盒子中找出字典序最大的字符串 I

3403. 从盒子中找出字典序最大的字符串 I 题目链接&#xff1a;3403. 从盒子中找出字典序最大的字符串 I 代码如下&#xff1a; class Solution { public:string answerString(string word, int numFriends) {if (numFriends 1) {return word;}string res;for (int i 0;i &…...

深入解析C++中的extern关键字:跨文件共享变量与函数的终极指南

&#x1f680; C extern 关键字深度解析&#xff1a;跨文件编程的终极指南 &#x1f4c5; 更新时间&#xff1a;2025年6月5日 &#x1f3f7;️ 标签&#xff1a;C | extern关键字 | 多文件编程 | 链接与声明 | 现代C 文章目录 前言&#x1f525;一、extern 是什么&#xff1f;&…...

在WSL2的Ubuntu镜像中安装Docker

Docker官网链接: https://docs.docker.com/engine/install/ubuntu/ 1、运行以下命令卸载所有冲突的软件包&#xff1a; for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done2、设置Docker…...