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

Qt Creator创建一个用户登录界面

目录

1 界面设计

2 代码

2.1 登录界面

2.2 注册界面

2.3 登陆后的界面

3 完整资源


        这里主要记录了如何使用Qt Creator创建一个用户登录界面,能够实现用户的注册和登录功能,注册的用户信息存储在了一个文件之中,在登录时可以比对登录信息和文件存储信息,已确认用户是否存在,如果不存在也可以通过注册功能进行注册。

1 界面设计

主要分为3个界面:登录界面、注册界面、登录后的界面

2 代码

2.1 登录界面

登录界面命名对于文件为widget.h、widget.c

widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <form.h>
#include <form01.h>QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACEclass Widget : public QWidget
{Q_OBJECTpublic:Form *form = new Form();         // define a objectForm01 *form01 = new Form01();   // Loginpublic:Widget(QWidget *parent = nullptr);~Widget();private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();private:Ui::Widget *ui;
};
#endif // WIDGET_H

widget.c

#include "widget.h"
#include "ui_widget.h"
#include "QDebug"
#include "main.h"
#include "QDir"
#include "QMessageBox"Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);connect(this->form, &Form::BackSig, this, [=](){this->form->hide();this->show();});}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{// this->hide();// this->close();qDebug() << "Change page to Login";// gain context about lineEdit and judge and ...QString path = QDir::currentPath(); // 获取当前工程所在路径std::string user_pwd;  //std::string part1;   // useranmestd::string part2;   // passwordint flag = 1;std::ifstream infile("/root/QT_developer/File/user_table.txt");if (!infile.is_open()) {std::cerr << "Unable to open file!" << std::endl;}//std::string line;QString In_username = ui->lineEdit->text();QString In_password = ui->lineEdit_2->text();part1 = In_username.toStdString();part2 = In_password.toStdString();user_pwd = part1 + ":" + part2;if(In_password.isEmpty()){QMessageBox::information(this, "Tips", "In_password is empty!");}else if(In_username.isEmpty()){QMessageBox::information(this, "Tips", "In_usename is empty!");}else{while (std::getline(infile, line)) {  // gain data on a lineif(user_pwd == line){flag = 0;infile.close();this->close();ui->lineEdit->clear();ui->lineEdit_2->clear();QMessageBox::information(this, "Tips", "Login success!");In_username.clear();In_password.clear();form01->show();break;}}if(flag == 1){ui->lineEdit->clear();ui->lineEdit_2->clear();QMessageBox::information(this, "Tips", "username or password is error!");In_username.clear();In_password.clear();}}
}void Widget::on_pushButton_2_clicked()
{// this->hide();// this->close();qDebug() << "Change page to Register";form->show();
}void Widget::on_pushButton_3_clicked()
{this->close();qDebug() << "Quit";
}

2.2 注册界面

注册界面命名对于文件为form.h、form.c

form.h

#ifndef FORM_H
#define FORM_H#include <QWidget>namespace Ui {
class Form;
}class Form : public QWidget
{Q_OBJECTpublic:explicit Form(QWidget *parent = nullptr);~Form();public:void Open_file();private slots:void on_pushButton_2_clicked();void on_pushButton_clicked();private:Ui::Form *ui;signals:void BackSig();  // define a signal without arg.
};#endif // FORM_H

form.c

#include "form.h"
#include "ui_form.h"
#include "qdebug.h"
#include "widget.h"
#include "QLineEdit"
#include "QMessageBox"
#include "main.h"
#include "QDir"Form::Form(QWidget *parent) :QWidget(parent),ui(new Ui::Form)
{ui->setupUi(this);// this->show();}Form::~Form()
{delete ui;
}void Form::on_pushButton_2_clicked()
{qDebug() << "Back";emit this->BackSig();}void Form::on_pushButton_clicked()
{///QString path = QDir::currentPath(); // 获取当前工程所在路径std::size_t found; // 查找冒号的位置std::string user_pwd;  // Concatenated username and passwordstd::string part1;   // useranmestd::string part2;   // passwordstd::string line;int flag = 1;std::ofstream outfile; // ready for writing// std::ifstream infile(path.toStdString() + "user_table.txt");std::ifstream infile("/root/QT_developer/File/user_table.txt");  // Absolute pathif (!infile.is_open()) {              // Determine whether the opening is successfulstd::cerr << "Unable to open file!" << std::endl;}///// gain dataQString username = ui->lineEdit->text();QString password = ui->lineEdit_2->text();QString password_firm = ui->lineEdit_3->text();// pan duan yong hu ming shi fou chong fuif(username.isEmpty()){qDebug() << "username can't is empty";QMessageBox::information(this, "Tips", "username can't is empty");}else if(password.isEmpty()){QMessageBox::information(this, "Tips", "password can't is empty");}else if(password_firm.isEmpty()){QMessageBox::information(this, "Tips", "password_firm can't is empty");}else{// judgeif(password != password_firm){ui->lineEdit->clear();  // clearui->lineEdit_2->clear();ui->lineEdit_3->clear();QMessageBox::information(this, "Tips", "password != password_firm!");username.clear();    // clearpassword.clear();password_firm.clear();}else{while (std::getline(infile, line)) {  // gain data on a linefound = line.find(':');   // find :if (found != std::string::npos) {part1 = line.substr(0, found); // 从开始到冒号前的部分qDebug() << "part1-username: ";cout << "part1-username: " << part1;}//if(QString::fromStdString(part1) == username){flag = 0;infile.close();ui->lineEdit->clear();ui->lineEdit_2->clear();ui->lineEdit_3->clear();QMessageBox::information(this, "Tips", "username has been exist!");username.clear();password.clear();password_firm.clear();break;}}if(flag == 1){QMessageBox::information(this, "Tips", "Register success!");part1 = username.toStdString();part2 = password.toStdString();user_pwd = part1 + ":" + part2;outfile.open("/root/QT_developer/File/user_table.txt", ios::in | std::ios::out | std::ios::app);outfile << user_pwd << endl;outfile.close();ui->lineEdit->clear();ui->lineEdit_2->clear();ui->lineEdit_3->clear();username.clear();password.clear();password_firm.clear();}}}}

2.3 登陆后的界面

登录后的界面命名对于文件为form01.h、form01.c

form01.h

#ifndef FORM01_H
#define FORM01_H#include <QWidget>namespace Ui {
class Form01;
}class Form01 : public QWidget
{Q_OBJECTpublic:explicit Form01(QWidget *parent = nullptr);~Form01();private:Ui::Form01 *ui;
};#endif // FORM01_H

form01.c

#include "form01.h"
#include "ui_form01.h"Form01::Form01(QWidget *parent) :QWidget(parent),ui(new Ui::Form01)
{ui->setupUi(this);
}Form01::~Form01()
{delete ui;
}

3 完整资源

按照以上代码就能实现,如果有需要这是完整代码。也可以私我。

https://download.csdn.net/download/qq_51458770/89492862

相关文章:

Qt Creator创建一个用户登录界面

目录 1 界面设计 2 代码 2.1 登录界面 2.2 注册界面 2.3 登陆后的界面 3 完整资源 这里主要记录了如何使用Qt Creator创建一个用户登录界面&#xff0c;能够实现用户的注册和登录功能&#xff0c;注册的用户信息存储在了一个文件之中&#xff0c;在登录时可以比对登录信息…...

等保测评练习卷14

等级保护初级测评师试题14 姓名&#xff1a; 成绩&#xff1a; 判断题&#xff08;10110分&#xff09; 1. 方案编制活动中测评对象确定、测评指…...

学懂C#编程:常用高级技术——学会C#多线程开发(三):学会线程池的使用

在C#中&#xff0c;线程池&#xff08;ThreadPool&#xff09;是一种用于管理线程的机制&#xff0c;它可以有效地重用线程&#xff0c;减少线程创建和销毁的开销&#xff0c;从而提高程序的性能。线程池通常用于执行不需要立即完成的任务&#xff0c;如后台任务、异步操作等。…...

maven-gpg-plugin插件

开源项目SDK&#xff1a;https://github.com/mingyang66/spring-parent 个人文档&#xff1a;https://mingyang66.github.io/raccoon-docs/#/ 一、敏感信息泄漏警告 执行mvn install或mvn deploy时控制台会报如下告警&#xff1a; [WARNING] Parameter passphrase (user pr…...

Linux——echo命令,管道符,vi/vim 文本编辑器

1.echo 命令 作用 向终端设备上输出字符串或变量的存储数据 格式 echo " 字符串 " echo $ 变 量名 [rootserver ~] # echo $SHELL # 输出变量的值必须加 $ /bin/bash [rootserver ~] # str1" 我爱中国 " # 自定义变量 echo 重定向输出到文件 ec…...

CISCN--西南半决赛--pwn

1.vuln 这是主函数&#xff0c;数一下就发现可以溢出最后的0x4008d0 然后会执行到这里&#xff0c;逻辑就是在v0上写shellcode&#xff0c;不过执行写0x10&#xff0c;不够sh&#xff0c;很明显要先read。 以下是exp: from pwn import * context.archamd64 ioprocess(./vuln)…...

DIYGW UniApp低代码可视化平台:高效、灵活、安全的应用开发新途径

一、引言 在数字化快速发展的今天&#xff0c;企业对于快速构建多端应用的需求日益增长。然而&#xff0c;传统的应用开发方式往往面临周期长、成本高、技术门槛高等问题。为了解决这些问题&#xff0c;DIYGW UniApp低代码可视化平台应运而生&#xff0c;它以高效率、多端使用…...

Python爬虫技术及其原理探秘

导言 随着互联网的发展&#xff0c;大量的数据被存储在网络上&#xff0c;而我们需要从中获取有用的信息。Python作为一种功能强大且易于学习的编程语言&#xff0c;被广泛用于网络爬虫的开发。本文将详细介绍Python爬虫所需的技术及其原理&#xff0c;并提供相关的代码案例。…...

堆和栈的区别及应用场景

堆和栈的区别及应用场景 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01; 在计算机科学和编程领域&#xff0c;堆&#xff08;Heap&#xff09;和栈&#xff08…...

vant的dialog触发了其他overlay

原代码: <!-- dialog --><van-dialog v-model"showTipsDialog" title"温馨提示"><p>dialog内容</p></van-dialog><!-- overlay --><van-overlay style"display: flex" :show"showLoadingOverlay&q…...

Linux驱动开发笔记(十二)并发与竞争

文章目录 前言一、并发与竞争的引入1.1 并发1.2 竞争1.3 解决方法 二、原子操作2.1 概念2.2 使用方法 三、自旋锁3.1 概念3.2 使用方法3.3 自旋锁死锁 四、信号量4.1 概念4.2 使用方法 五、互斥锁5.1 概念5.2 使用方法 前言 Linux的子系统我们已经大致学习完了&#xff0c;笔者…...

【Mac】Listen 1 for Mac(最强的音乐搜索工具)软件介绍

软件介绍 Listen 1 for Mac 是一款非常方便的音乐播放软件&#xff0c;主要功能是集成多个音乐平台&#xff0c;让用户可以方便地搜索、播放和管理音乐。它是一个用 Python 语言开发的免费开源综合音乐搜索工具项目&#xff0c;最大的亮点在于可以搜索和播放来自网易云音乐&am…...

nginx 1024 worker_connections are not enough while connecting to upstream

现象 请求api响应慢&#xff0c;甚至出现504 gateway timeout&#xff0c;重启后端服务不能恢复&#xff0c;但重启nginx可以恢复。 解决方案 worker_connections使用了默认值 1024&#xff0c;当流量增长时&#xff0c;导致连接不够 在nginx.conf中修改连接数就可以了&…...

在Ubuntu 16.04上安装和配置Elasticsearch的方法

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站。 简介 Elasticsearch 是一个用于实时分布式搜索和数据分析的平台。它因易用性、强大功能和可扩展性而备受欢迎。 Elasticsearch 支持 R…...

C#给SqlSugar封装一个单例类

.NET兼职社区 可以直接用&#xff0c;轻量方便&#xff0c;无需重复造轮子。 这里只对CRUD进行封装&#xff0c;我的应用比较简单。 using SqlSugar; using System.Collections.Generic;namespace MusicApp.Assist {internal class SqlSugarAssist{private static readonly ob…...

Postman接口测试工具的原理及应用详解(六)

本系列文章简介&#xff1a; 在当今软件开发的世界中&#xff0c;接口测试作为保证软件质量的重要一环&#xff0c;其重要性不言而喻。随着前后端分离开发模式的普及&#xff0c;接口测试已成为连接前后端开发的桥梁&#xff0c;确保前后端之间的数据交互准确无误。在这样的背景…...

【算法 之插入排序 原理及案例】

插入排序原理&#xff1a; 插入排序&#xff08;Insertion Sort&#xff09;是一种简单直观的排序算法。它的工作原理是通过构建有序序列&#xff0c;对于未排序数据&#xff0c;在已排序序列中从后向前扫描&#xff0c;找到相应位置并插入。插入排序在实现上&#xff0c;通常…...

第一节:如何开发第一个spring boot3.x项目(自学Spring boot 3.x的第一天)

大家好&#xff0c;我是网创有方&#xff0c;从今天开始&#xff0c;我会记录每篇我自学spring boot3.x的经验。只要我不偷懒&#xff0c;学完应该很快&#xff0c;哈哈&#xff0c;更新速度尽可能快&#xff0c;想和大佬们一块讨论&#xff0c;如果需要讨论的欢迎一起评论区留…...

JS逆向:由 words 、sigBytes 引发的一系列思考与实践

【作者主页】&#xff1a;小鱼神1024 【擅长领域】&#xff1a;JS逆向、小程序逆向、AST还原、验证码突防、Python开发、浏览器插件开发、React前端开发、NestJS后端开发等等 在做JS逆向时&#xff0c;你是否经常看到 words 和 sigBytes 这两个属性呢&#xff0c;比如&#xff…...

计算机的错误计算(十五)

摘要 介绍历史上由于计算精度问题引起的灾难或事件。 今天换个话题&#xff0c;说说历史上曾经发生过的一些事件。 1961 年 , 美国麻省理工学院气象学家洛伦兹在仿真天气预报时 , 将 0.506127 舍入到 0.506 , 所得计算结果大相径庭 ! 这种“差之毫厘 , 谬以千里”的现象…...

RocketMQ延迟消息机制

两种延迟消息 RocketMQ中提供了两种延迟消息机制 指定固定的延迟级别 通过在Message中设定一个MessageDelayLevel参数&#xff0c;对应18个预设的延迟级别指定时间点的延迟级别 通过在Message中设定一个DeliverTimeMS指定一个Long类型表示的具体时间点。到了时间点后&#xf…...

2025年能源电力系统与流体力学国际会议 (EPSFD 2025)

2025年能源电力系统与流体力学国际会议&#xff08;EPSFD 2025&#xff09;将于本年度在美丽的杭州盛大召开。作为全球能源、电力系统以及流体力学领域的顶级盛会&#xff0c;EPSFD 2025旨在为来自世界各地的科学家、工程师和研究人员提供一个展示最新研究成果、分享实践经验及…...

使用分级同态加密防御梯度泄漏

抽象 联邦学习 &#xff08;FL&#xff09; 支持跨分布式客户端进行协作模型训练&#xff0c;而无需共享原始数据&#xff0c;这使其成为在互联和自动驾驶汽车 &#xff08;CAV&#xff09; 等领域保护隐私的机器学习的一种很有前途的方法。然而&#xff0c;最近的研究表明&…...

生成 Git SSH 证书

&#x1f511; 1. ​​生成 SSH 密钥对​​ 在终端&#xff08;Windows 使用 Git Bash&#xff0c;Mac/Linux 使用 Terminal&#xff09;执行命令&#xff1a; ssh-keygen -t rsa -b 4096 -C "your_emailexample.com" ​​参数说明​​&#xff1a; -t rsa&#x…...

【android bluetooth 框架分析 04】【bt-framework 层详解 1】【BluetoothProperties介绍】

1. BluetoothProperties介绍 libsysprop/srcs/android/sysprop/BluetoothProperties.sysprop BluetoothProperties.sysprop 是 Android AOSP 中的一种 系统属性定义文件&#xff08;System Property Definition File&#xff09;&#xff0c;用于声明和管理 Bluetooth 模块相…...

MySQL用户和授权

开放MySQL白名单 可以通过iptables-save命令确认对应客户端ip是否可以访问MySQL服务&#xff1a; test: # iptables-save | grep 3306 -A mp_srv_whitelist -s 172.16.14.102/32 -p tcp -m tcp --dport 3306 -j ACCEPT -A mp_srv_whitelist -s 172.16.4.16/32 -p tcp -m tcp -…...

html-<abbr> 缩写或首字母缩略词

定义与作用 <abbr> 标签用于表示缩写或首字母缩略词&#xff0c;它可以帮助用户更好地理解缩写的含义&#xff0c;尤其是对于那些不熟悉该缩写的用户。 title 属性的内容提供了缩写的详细说明。当用户将鼠标悬停在缩写上时&#xff0c;会显示一个提示框。 示例&#x…...

初学 pytest 记录

安装 pip install pytest用例可以是函数也可以是类中的方法 def test_func():print()class TestAdd: # def __init__(self): 在 pytest 中不可以使用__init__方法 # self.cc 12345 pytest.mark.api def test_str(self):res add(1, 2)assert res 12def test_int(self):r…...

【VLNs篇】07:NavRL—在动态环境中学习安全飞行

项目内容论文标题NavRL: 在动态环境中学习安全飞行 (NavRL: Learning Safe Flight in Dynamic Environments)核心问题解决无人机在包含静态和动态障碍物的复杂环境中进行安全、高效自主导航的挑战&#xff0c;克服传统方法和现有强化学习方法的局限性。核心算法基于近端策略优化…...

QT3D学习笔记——圆台、圆锥

类名作用Qt3DWindow3D渲染窗口容器QEntity场景中的实体&#xff08;对象或容器&#xff09;QCamera控制观察视角QPointLight点光源QConeMesh圆锥几何网格QTransform控制实体的位置/旋转/缩放QPhongMaterialPhong光照材质&#xff08;定义颜色、反光等&#xff09;QFirstPersonC…...