mainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "new_resiger.h"
#include<QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->forget->setText("忘记密码");
ui->loading->setText("登陆");
ui->password->setText("密码");
ui->loadauto->setText("自动登陆");
ui->username->setText("用户名");
ui->remember->setText("记住密码");
ui->register_2->setText("注册");
ui->line2->setEchoMode(QLineEdit::Password);
connect(ui->register_2,&QPushButton::clicked,this,&MainWindow::onresigerclicked);
ui->label->setPixmap(QPixmap("://userName.jpg"));
ui->label->setScaledContents(true);
ui->label_2->setPixmap(QPixmap(":/passwd.jpg"));
ui->label_2->setScaledContents(true);
ui->loading->setIcon(QIcon("://login.png"));
ui->hqyj->setPixmap(QPixmap("://logo.png"));
ui->hqyj->setScaledContents(true);
connect(ui->loading,&QPushButton::clicked,[&]()
{
if(ui->line2->text() != "123456" || ui->line1->text()!="admin")
{
QMessageBox msgbox(QMessageBox::Warning,"warning","输入账号或密码错误\n是否重新输入",QMessageBox::Ok | QMessageBox::No);
//msgbox.warning(this,"warning","输入账号或密码错误\n是否重新输入",QMessageBox::Ok | QMessageBox::No);
int res = msgbox.exec();
if(res == QMessageBox::No)
this->close();
else
{
ui->line1->clear();
ui->line2->clear();
}
}
else if(ui->line2->text() == "123456" && ui->line1->text() =="admin")
{
//QMessageBox msgbox;
QMessageBox msgbox(QMessageBox::Warning,"提示","恭喜你,登录成功",QMessageBox::Ok );
int res = msgbox.exec();
if(res == QMessageBox::Ok)
this->close();
}
});
this->setWindowTitle("用户登录");
ui->onclose->setIcon(QIcon("://cancel.png"));
ui->onclose->setText("退出");
ui->loading->setFixedSize(80,30);
ui->onclose->setFixedSize(ui->loading->width(),ui->loading->height());
connect(ui->onclose,&QPushButton::clicked,[&](){
QMessageBox msgbox(QMessageBox::Warning,"警告","您是否确认要退出登录",QMessageBox::Yes | QMessageBox::No );
int res = msgbox.exec();
if(res == QMessageBox::Yes)
{
this->close();
}
});
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onresigerclicked()
{
new_resiger *w = new new_resiger;
w->show();
}
结果演示:
登录界面:
密码输入错误:
密码输入正确:
点击退出: