(Visual Studio + Qt)编写登陆界面

界面展示在这里插入图片描述

工具版本

Visual Studio 2022 + Qt6.5.2_msvc2019_64

代码

//QLogin.h
#pragma once

#include <QtWidgets/QWidget>
#include "ui_QLogin.h"

class QLogin : public QWidget
{
    Q_OBJECT

public:
    QLogin(QWidget *parent = nullptr);
    ~QLogin();

private:
    Ui::QLoginClass ui;

private slots:
    void on_pushButton_Login_clicked();
};

//QLogin.cpp
/*******************************************
File name : QLogin.cpp
Founder : qihaoyu
Created time : 2023-08-10
Project Name : No
Module name : login interface module
Description :
1、login interface ( account, password input box ; login button )
********************************************/
#include "QLogin.h"
#include <QDateTime>
#include <QDebug>
#include <QMessageBox>

QLogin::QLogin(QWidget *parent)
    : QWidget(parent)
{
    ui.setupUi(this);

    //Account
    ui.AccountEdit->setPlaceholderText("Account");

    //Password
    ui.PasswordEdit->setPlaceholderText("Password");
    ui.PasswordEdit->setEchoMode(QLineEdit::Password);

    //Login
    ui.LoginBtn->setText("Login");
    ui.LoginBtn->setShortcut(Qt::Key_Return);//Shortcut key trigger
    connect(ui.LoginBtn, SIGNAL(clicked()), this, SLOT(on_pushButton_Login_clicked()));
}

QLogin::~QLogin()
{
}

void QLogin::on_pushButton_Login_clicked() 
{
    //The hexadecimal of the current date
    QDateTime datetime = QDateTime::currentDateTime();
    QString datetime_hex = QString::number(datetime.toString("yyyyMMddhh").toInt(), 16);

    if (QString(ui.AccountEdit->text()) == "qihaoyu") 
    {
        if (QString(ui.PasswordEdit->text()) == datetime_hex)
        {
            QMessageBox messagebox(QMessageBox::NoIcon, "Presentation", "Successful login!", QMessageBox::Ok, this);
            messagebox.exec();

            //Programming

            //delete the login record
            ui.AccountEdit->setText("");
            ui.PasswordEdit->setText("");

            this->close();
        }
        else if (QString(ui.PasswordEdit->text()) == "") {
            QMessageBox messagebox(QMessageBox::NoIcon, "Presentation", "Please enter the password!", QMessageBox::Ok, this);
            messagebox.exec();
        }
        else {
            QMessageBox messagebox(QMessageBox::NoIcon, "Presentation", "Password error!", QMessageBox::Ok, this);
            messagebox.exec();
            ui.PasswordEdit->setText("");
        }
    }
    else if(QString(ui.AccountEdit->text()) == ""){
        QMessageBox messagebox(QMessageBox::NoIcon, "Presentation", "Please enter your account!", QMessageBox::Ok, this);
        messagebox.exec();
    }
    else {
        QMessageBox messagebox(QMessageBox::NoIcon, "Presentation", "Account Error!", QMessageBox::Ok, this);
        messagebox.exec();
        ui.AccountEdit->setText("");
    }
}

源码

github

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值