#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); this->setWindowTitle("不知名系统"); this->setWindowIcon(QIcon(":logo")); } MainWindow::~MainWindow() { delete ui; delete register_widget; // 释放注册页 } 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() <login_success(); // 广播登录成功 break; } } file.close(); } void MainWindow::on_clearBtn_clicked() { ui->idEdit->clear(); ui->passwordEdit->clear(); } void MainWindow::on_exitBtn_clicked() { this->close(); }