完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面
如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户迪纳基Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
要求:基于属性版和基于静态成员函数版至少各用一个
widget.h
#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QMessageBox>namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = nullptr);~Widget();private:Ui::Widget *ui;
public slots:void on_logButton_clicked();void Log_yes();
signals:void log_btn();
private slots:void on_canButton_clicked();
};#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);this->setWindowFlag(Qt::FramelessWindowHint);this->setAttribute(Qt::WA_TranslucentBackground);this->setWindowIcon(QIcon("C:\\Users\\13103321519\\Desktop\\pictrue\\pictrue\\qq.png"));this->setWindowTitle("QQ");//connect(ui->logButton,&QPushButton::clicked,this,&Widget::log_btn);}Widget::~Widget()
{delete ui;
}void Widget::on_logButton_clicked()
{if(ui->nameEdit->text() == "admin" && ui->passEdit->text() == "123456"){QMessageBox msg(QMessageBox::Information,"登陆成功","登陆成功",QMessageBox::Yes,this);int ret = msg.exec();if(ret == QMessageBox::Yes){emit this->log_btn();this->close();}}else {emit this->Log_yes();}
}void Widget::Log_yes()
{QMessageBox msge(QMessageBox::Critical,"错误","账号密码不匹配,是否重新登陆",QMessageBox::Yes | QMessageBox::No,this);int ret = msge.exec();if(ret == QMessageBox::Yes){ui->passEdit->clear();}else {this->close();}
}void Widget::on_canButton_clicked()
{int ret = QMessageBox::question(this,"是否退出","您是否确定要退出登陆?",QMessageBox::Yes | QMessageBox::No);if(ret == QMessageBox::Yes){this->close();}
}
login.h
#ifndef LOGIN_H
#define LOGIN_H#include <QWidget>namespace Ui {
class Login;
}class Login : public QWidget
{Q_OBJECTpublic:explicit Login(QWidget *parent = nullptr);~Login();private:Ui::Login *ui;
public slots:void lobin();};#endif // LOGIN_H
login.cpp
#include "login.h"
#include "ui_login.h"Login::Login(QWidget *parent) :QWidget(parent),ui(new Ui::Login)
{ui->setupUi(this);
}Login::~Login()
{delete ui;
}void Login::lobin()
{this->show();
}
main.cpp
#include "widget.h"
#include "login.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Widget w;Login l;QObject::connect(&w,&Widget::log_btn,&l,&Login::lobin);w.show();return a.exec();
}