qfedu-qt-level/Project02/mainwindow.cpp

83 lines
1.8 KiB
C++
Raw Permalink Normal View History

2023-08-10 12:05:02 +08:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
2023-08-13 11:47:00 +08:00
this->setWindowTitle("不知名系统");
this->setWindowIcon(QIcon(":logo"));
2023-08-10 12:05:02 +08:00
}
MainWindow::~MainWindow()
{
delete ui;
2023-08-13 11:47:00 +08:00
delete register_widget; // 释放注册页
2023-08-10 12:05:02 +08:00
}
2023-08-13 11:47:00 +08:00
void MainWindow::on_registerBtn_clicked()
{
register_widget = new RegisterWidget();
register_widget->show();
}
void MainWindow::on_loginBtn_clicked()
{
// debug 模式: 无密码登录
// emit this->login_success(); // 广播登录成功
// 密码验证登录
// QString id = ui->idEdit->text();
// QString password = ui->passwordEdit->text();
// if(id == "123" && password == "321"){
// emit this->login_success(); // 广播登录成功
// }
// else{
// QMessageBox::critical(this,"账号或密码错误","请检查用户名或密码");
// return;
// }
// "./userdata.txt"
QFile file("./userdata.txt");
if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
{
QMessageBox::warning(this,"警告","数据库为空,请先注册");
return;
}
QTextStream in(&file);
QString name = ui->idEdit->text();
QString pwd = ui->passwordEdit->text();
QString line = "";
while((line = in.readLine()) != "")
{
qDebug() <<line;
QStringList lineInfo = line.split(",");
if(lineInfo.contains(name)&&lineInfo.contains(pwd))
{
emit this->login_success(); // 广播登录成功
break;
}
}
file.close();
}
void MainWindow::on_clearBtn_clicked()
{
ui->idEdit->clear();
ui->passwordEdit->clear();
}
void MainWindow::on_exitBtn_clicked()
{
this->close();
}