效果:
核心代码:
#include "simpleapp.h"
#include "ui_simpleapp.h"
#include <QMessageBox>
SimpleApp::SimpleApp(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::SimpleApp)
{
ui->setupUi(this);
}
SimpleApp::~SimpleApp()
{
delete ui;
}
void SimpleApp::on_btnExit_clicked()
{
close();
}
// 此项目参考地址:
// https://www.youtube.com/watch?v=6FjOY28Nl5g&ab_channel=HelloC%26CPPByProgrammingKnowledge
void SimpleApp::on_btnLongin_clicked()
{
QString name = ui->usernameTxt->text();
QString pass = ui->passwordTxt->text();
if (name == "admin" && pass == "123") {
QMessageBox::information(this, "Login", "账号密码都正确!");
// 先隐藏登录窗口。
hide();
// 显示一个新的窗口。
secDialog = new SecDialog(this);
secDialog->show();
} else {
QMessageBox::warning(this, "Login", "账号或密码不正确!请检查!");
}
}
完整项目已经上传, 免积分下载,https://download.csdn.net/download/waterHBO/89547456