QT 简单的登录界面 您所在的位置:网站首页 qt登录界面源码 QT 简单的登录界面

QT 简单的登录界面

2023-10-18 02:35| 来源: 网络整理| 查看: 265

一、描述 有登录界面、注册界面,用到sqlite数据库保存账号和密码,界面还没有布局美化等,只实现了最基本的功能。

二、界面及功能介绍 1、登录界面在这里插入图片描述2、注册界面在这里插入图片描述 3、主界面 没想好弄啥功能,于是就弄了两个按钮。 在这里插入图片描述 4、文件结构 在这里插入图片描述

三、代码

1.login.pro

QT += core gui QT += sql widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += 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.0 SOURCES += \ general.cpp \ logindialog.cpp \ logondialog.cpp \ main.cpp \ widget.cpp HEADERS += \ general.h \ logindialog.h \ logondialog.h \ widget.h FORMS += \ logindialog.ui \ logondialog.ui \ widget.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target

2.general.h

#ifndef GENERAL_H #define GENERAL_H #include #include #include #include #include #include QSqlQuery connect_sqlite(); void sql_close(); #endif // GENERAL_H

3.logindialog.h

#ifndef LOGINDIALOG_H #define LOGINDIALOG_H #include #include "logondialog.h" #include "ui_logondialog.h" namespace Ui { class LoginDialog; } class LoginDialog : public QDialog { Q_OBJECT public: explicit LoginDialog(QWidget *parent = nullptr); ~LoginDialog(); LogonDialog logondialog; private slots: void on_pushButton_clicked(); void on_pushButton_2_clicked(); void on_pushButton_3_clicked(); void on_pushButton_4_clicked(); private: Ui::LoginDialog *ui; }; #endif // LOGINDIALOG_H

4.logondialog.h

#ifndef LOGONDIALOG_H #define LOGONDIALOG_H #include #include "general.h" namespace Ui { class LogonDialog; } class LogonDialog : public QDialog { Q_OBJECT public: explicit LogonDialog(QWidget *parent = nullptr); ~LogonDialog(); public: Ui::LogonDialog *ui; private slots: void on_pushButton_2_clicked(); void on_pushButton_clicked(); }; #endif // LOGONDIALOG_H

5.widget.h

#ifndef WIDGET_H #define WIDGET_H #include #include "logindialog.h" QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); private slots: void on_pushButton_2_clicked(); private: Ui::Widget *ui; }; #endif // WIDGET_H

6.general.cpp

#include "general.h" QSqlDatabase db; QSqlQuery connect_sqlite() { //验证数据库连接是否存在,不存在就创建一个 if(QSqlDatabase::contains("first")) { db = QSqlDatabase::database("first"); } else { //用的是sqlite数据库 db = QSqlDatabase::addDatabase("QSQLITE","first"); db.setDatabaseName("QtQq.db");//设置数据库名称,若不存在自动创建一个 db.setUserName("zhanglinghua");//设置数据库账号,不用也没啥问题 db.setPassword("123456"); //设置数据库密码,不用也没啥问题 } bool a = db.open(); //打开数据库,必须打开才能进行增删查改的操作 if(!a) { qDebug()lineEdit_2->text();//获取密码 //qDebug()


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有