界面展示
工具版本
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("");
}
}