国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

QT 簡單的登錄界面

這篇具有很好參考價值的文章主要介紹了QT 簡單的登錄界面。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、描述
有登錄界面、注冊界面,用到sqlite數(shù)據(jù)庫保存賬號和密碼,界面還沒有布局美化等,只實現(xiàn)了最基本的功能。

二、界面及功能介紹
1、登錄界面QT 簡單的登錄界面2、注冊界面QT 簡單的登錄界面
3、主界面
沒想好弄啥功能,于是就弄了兩個按鈕。
QT 簡單的登錄界面
4、文件結構
QT 簡單的登錄界面

三、代碼

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 <QSqlDatabase>
#include <QDebug>
#include <QStringList>
#include <QSqlQuery>
#include <iostream>
#include <QMessageBox>


QSqlQuery connect_sqlite();
void sql_close();


#endif // GENERAL_H

3.logindialog.h

#ifndef LOGINDIALOG_H
#define LOGINDIALOG_H

#include <QDialog>
#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 <QDialog>
#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 <QWidget>
#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()
{
    //驗證數(shù)據(jù)庫連接是否存在,不存在就創(chuàng)建一個
    if(QSqlDatabase::contains("first"))
    {
        db = QSqlDatabase::database("first");
    }
    else
    {
        //用的是sqlite數(shù)據(jù)庫
        db = QSqlDatabase::addDatabase("QSQLITE","first");
        db.setDatabaseName("QtQq.db");//設置數(shù)據(jù)庫名稱,若不存在自動創(chuàng)建一個
        db.setUserName("zhanglinghua");//設置數(shù)據(jù)庫賬號,不用也沒啥問題
        db.setPassword("123456");      //設置數(shù)據(jù)庫密碼,不用也沒啥問題
    }
    bool a = db.open();            //打開數(shù)據(jù)庫,必須打開才能進行增刪查改的操作
    if(!a)
    {
        qDebug()<<"數(shù)據(jù)庫打開失敗";
        exit(100);
    }
    else
    {
        qDebug()<<"數(shù)據(jù)庫打開成功";
    }
    QSqlQuery sql_query(db);
    return sql_query;
}

void sql_close()
{
    db.close();
}

7.logindialog.cpp

#include "logindialog.h"
#include "ui_logindialog.h"

LoginDialog::LoginDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LoginDialog)
{
    ui->setupUi(this);
}

LoginDialog::~LoginDialog()
{
    delete ui;
}

//驗證登錄函數(shù)
void LoginDialog::on_pushButton_clicked()
{
    QSqlQuery sql_query = connect_sqlite();
    QString user = ui->lineEdit->text();//獲取賬號
    QString pwd = ui->lineEdit_2->text();//獲取密碼

    //qDebug()<<user<<pwd;

    //先驗證賬號是否存在,若存在,再驗證密碼
    QString user_sql = QString("select user from users;");
    sql_query.exec(user_sql);
    bool flag=0;
    while(sql_query.next())
    {
        if(sql_query.value(0).toString()==user)
        {
            flag=1;
        }
    }
    if(flag==1)
    {
        QString sql = QString("select passwd from users where user = '%1'").arg(user);//驗證賬號密碼
        sql_query.prepare(sql);
        sql_query.exec();
        QString sql_pwd;
        while(sql_query.next())
        {
            sql_pwd = sql_query.value(0).toString();
            qDebug()<<"密碼"<<sql_pwd;
        }

        if(pwd == sql_pwd)
        {
            qDebug()<<"登錄成功";
            accept();
        }
        else
        {
            QMessageBox::information(this,QObject::tr("登錄提示"),QObject::tr("賬號或密碼錯誤"),QMessageBox::Ok,QMessageBox::Ok);
        }
    }
    else
    {
        QMessageBox::information(this,QObject::tr("登錄提示"),QObject::tr("未發(fā)現(xiàn)該賬號,請先注冊。"),QMessageBox::Ok,QMessageBox::Ok);
    }


}

//關閉注冊窗口
void LoginDialog::on_pushButton_2_clicked()
{
    close();
}


//顯示注冊窗口
void LoginDialog::on_pushButton_3_clicked()
{
    LogonDialog lgo;
    lgo.setWindowTitle("注冊");
    lgo.exec();
}

//忘記密碼函數(shù)
void LoginDialog::on_pushButton_4_clicked()
{
    QMessageBox::information(this,QObject::tr("密碼"),QObject::tr("忘記了也沒辦法,大哥重新注冊一個吧。"),QMessageBox::Ok,QMessageBox::Ok);
}

8.logondialog.cpp

#include "logondialog.h"
#include "ui_logondialog.h"

LogonDialog::LogonDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LogonDialog)
{
    ui->setupUi(this);
}

LogonDialog::~LogonDialog()
{
    delete ui;
}

//注冊功能實現(xiàn)函數(shù)
void LogonDialog::on_pushButton_2_clicked()
{

    QString user = ui->lineEdit->text();
    QString pwd = ui->lineEdit_2->text();
    QString enter_pwd = ui->lineEdit_3->text();
    if(user==""||pwd==""||enter_pwd=="")
    {
        QMessageBox::information(this,QObject::tr("注冊提示"),QObject::tr("輸入不能為空,請重新輸入!"),QMessageBox::Ok,QMessageBox::Ok);
    }
    else
    {
         QSqlQuery sql_query=connect_sqlite();
         QString logon_sql = QString("select user from users;");
         sql_query.exec(logon_sql);
         while(sql_query.next())
         {
             if(sql_query.value(0).toString()==user)
             {
                 QMessageBox::information(this,QObject::tr("注冊提示"),QObject::tr("未能注冊,賬號已存在,請更換賬號后重新嘗試注冊!"),QMessageBox::Ok,QMessageBox::Ok);
             }
         }
         if(pwd!=enter_pwd)
         {
             QMessageBox::information(this,QObject::tr("注冊提示"),QObject::tr("未能注冊,兩次密碼輸入不一致,請重新輸入!"),QMessageBox::Ok,QMessageBox::Ok);
         }
         else
         {
             QString insert = QString("insert into users values('%1','%2');").arg(user).arg(pwd);

             if(sql_query.exec(insert))
             {
                 QMessageBox::information(this,QObject::tr("注冊提示"),QObject::tr("注冊成功!"),QMessageBox::Ok,QMessageBox::Ok);
             }
             else
             {
                 QMessageBox::information(this,QObject::tr("注冊提示"),QObject::tr("未能注冊,請嘗試重新注冊!"),QMessageBox::Ok,QMessageBox::Ok);
             }
         }

         sql_close();
    }
}

//關閉注冊窗口
void LogonDialog::on_pushButton_clicked()
{
    close();
}

9.main.cpp

#include "widget.h"

#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QStringList dr = QSqlDatabase::drivers();//查看有哪些數(shù)據(jù)驅動,原本想用MySQL數(shù)據(jù)庫,但是我qt里沒驅動,自己搗鼓了半天也沒成功,就直接用sqlite數(shù)據(jù)庫了
    foreach(QString driver,dr)
        qDebug()<<driver;


    QString sql = "create table users(user varchar(40) primary key,passwd varchar(40));";
    QString judgmen_table_exist = "select count(*) from users where user = 'z';";
    QSqlQuery sql_query1=connect_sqlite();

    bool flag = sql_query1.exec(judgmen_table_exist);
    if(!flag)
    {
        flag = sql_query1.exec(sql);
        if(flag)
        {
            qDebug()<<"user table create success";
        }
        else
        {
            qDebug()<<"user table create error";
        }
    }
    sql_close();
    LoginDialog logindialog;
    logindialog.setWindowTitle(QObject::tr("登錄"));
    if(logindialog.exec()==QDialog::Accepted)
    {
        Widget w;
        w.setWindowTitle(QObject::tr("QtQq"));
        w.show();
        return a.exec();
    }
    else
        return 0;
}

10.widget.cpp文章來源地址http://www.zghlxwxcb.cn/news/detail-507749.html

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

//重新登錄功能實現(xiàn)函數(shù)
void Widget::on_pushButton_2_clicked()
{
    close();
    LoginDialog ldg;
    if(ldg.exec()==QDialog::Accepted)
        show();
}

到了這里,關于QT 簡單的登錄界面的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內(nèi)容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • QT 簡單的登錄界面

    QT 簡單的登錄界面

    一、描述 有登錄界面、注冊界面,用到sqlite數(shù)據(jù)庫保存賬號和密碼,界面還沒有布局美化等,只實現(xiàn)了最基本的功能。 二、界面及功能介紹 1、登錄界面 2、注冊界面 3、主界面 沒想好弄啥功能,于是就弄了兩個按鈕。 4、文件結構 三、代碼 1.login.pro 2.general.h 3.logindialog.h 4

    2024年02月11日
    瀏覽(15)
  • QT day1簡單登錄界面

    QT day1簡單登錄界面

    widget.cpp文件代碼: ?widget.h文件

    2024年02月13日
    瀏覽(21)
  • Postman下載安裝注冊登錄簡介&登錄后界面簡介

    Postman下載安裝注冊登錄簡介&登錄后界面簡介

    如今,Postman的開發(fā)者已超過1000萬(來自官網(wǎng)),選擇使用Postman的原因如下: 1、簡單易用 - 要使用Postman,你只需登錄自己的賬戶,只要在電腦上安裝了Postman應用程序,就可以方便地隨時隨地訪問文件。 2、使用集合 - Postman允許用戶為他們的API調(diào)用創(chuàng)建集合。每個集合可以創(chuàng)建子

    2023年04月14日
    瀏覽(19)
  • Java登錄注冊界面v1.0

    Java登錄注冊界面v1.0

    登錄注冊界面 要求實現(xiàn)功能:登錄、注冊。 注冊: 1)檢查是否注冊過; 2)檢查字符串的合法性; 3)收集數(shù)據(jù)、存儲實例。 登錄: 1)檢查是否注冊過; 2)檢查是否登錄過; 3)檢查驗證密碼; 4)登錄成功,返回相關信息。 下面展示并分析登錄注冊界面v1.0的Java實現(xiàn)代

    2024年02月06日
    瀏覽(15)
  • 一個好看美觀的登錄注冊界面的實現(xiàn)

    一個好看美觀的登錄注冊界面的實現(xiàn)

    序言:之前介紹那個博客,然后自己搞了這個界面。最近有人和我要,把代碼給大家貼出來,提供參考。 首先是這個界面哈 然后呢,有那個javascript,就是綁定的登錄注冊時寫在外部文件中的。我給大家貼上。 注意啊上面一個登錄一個注冊。 這里同樣給出后端代碼,就是我們

    2024年02月11日
    瀏覽(26)
  • HTML 實現(xiàn)好看的登錄注冊界面(一)
  • Android學習(一)--用戶登錄注冊界面(界面跳轉+背景音樂)

    Android學習(一)--用戶登錄注冊界面(界面跳轉+背景音樂)

    目錄 1.功能要求 2.功能實現(xiàn)流程圖 3.功能演示 4.界面與功能 ?4.1登錄界面 4.1.1界面展示 4.1.2登錄界面功能簡介 4.1.3界面代碼 4.1.4登錄按鈕點擊事件 4.1.5退出按鈕點擊事件 ?4.1.6背景音樂點擊事件 4.1.7記住密碼 5.Java源碼 (1)三個界面布局,體現(xiàn)文本框、編輯框、單選按鈕、復

    2024年02月05日
    瀏覽(22)
  • 基于Java的界面開發(fā)【用戶注冊登錄】

    基于Java的界面開發(fā)【用戶注冊登錄】

    首先要清楚一個界面由哪些部分組成: ????????1、可視化部分:? 窗體、標簽、菜單、選項卡、按鈕...... ????????2、元素規(guī)則部分:? 顏色、尺寸、字體、布局 ????????3、內(nèi)容部分:? 文字、圖片 其次是所需代碼庫(java類庫):?? java.awt(元素規(guī)則類比較多)

    2024年02月06日
    瀏覽(25)
  • 用Android Studio編寫一個登錄界面和注冊界面并可以跳轉

    下面是使用 Android Studio 編寫一個簡單的登錄界面和注冊界面,并實現(xiàn)跳轉的示例代碼。 首先,在 res/layout 目錄下創(chuàng)建一個名為 activity_login.xml 的布局文件,作為登錄界面的布局: 接下來,在 res/layout 目錄下創(chuàng)建一個名為 activity_register.xml 的布局文件,作為注冊界面的布局:

    2024年04月09日
    瀏覽(33)
  • Android實現(xiàn)qq登錄注冊和好友列表界面

    Android實現(xiàn)qq登錄注冊和好友列表界面

    學習Android已經(jīng)有一個多月了,老師留了實現(xiàn)qq登陸注冊和好友列表的作業(yè),要求: 設計登錄界面,注冊界面和好友列表界面。 在登錄界面輸入用戶名“ admin ”,密碼“ abc123 ”后,判斷用戶名和密碼是否正確。 若用戶名或密碼錯誤則給出相應提示:“用戶名或密碼輸入有誤

    2024年02月02日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包