1.思维导图

2.完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示"登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面
如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮
YeslNo,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes/No,用户迪纳基Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
要求:基于属性版和基于静态成员函数版至少各用一个
widget.cpp
- #include "widget.h"
- #include "ui_widget.h"
-
- Widget::Widget(QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::Widget)
- {
- ui->setupUi(this);
- //添加动图
- QMovie *mv = new QMovie(":/picture/2310663110.gif");
- mv->setParent(this);
- ui->lab1->setMovie(mv);
- mv->start();
- ui->lab1->setScaledContents(true);
- //取消标题框
- this->setWindowFlag(Qt::FramelessWindowHint);
- //取消白框
- this->setAttribute(Qt::WA_TranslucentBackground);
- }
-
- Widget::~Widget()
- {
- delete ui;
- }
-
-
- void Widget::on_btn1_clicked()
- {//登录验证
- if(ui->led1->text()=="幻之"&&ui->led2->text()=="123456")
- {//基于静态成员函数版
- int res = QMessageBox::information(
- this,
- "提示",
- "登录成功",
- QMessageBox::Ok);
- if(res==QMessageBox::Ok)
- {
- this->close();
- emit sign();
- }
- }else
- {
- QMessageBox msg(//基于属性版
- QMessageBox::Warning,
- "提示",
- "账户和密码不匹配,是否重新登录",
- QMessageBox::Yes | QMessageBox::No,
- this);
- int res =msg.exec();
- if(res==QMessageBox::Yes)
- {
- ui->led2->setText("");
- }else
- {
- this->close();
- }
- }
-
-
- }
-
- void Widget::on_btn2_clicked()
- {//基于静态成员函数版
- int res = QMessageBox::question(
- this,
- "提示",
- "你是否确定要退出登录",
- QMessageBox::Yes | QMessageBox::No);
- if(res==QMessageBox::Yes)
- {
- this->close();
- }
- }
second.cpp
- #include "second.h"
- #include "ui_second.h"
-
- Second::Second(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::Second)
- {
- ui->setupUi(this);
- //取消标题框
- this->setWindowFlag(Qt::FramelessWindowHint);
- //取消白框
- this->setAttribute(Qt::WA_TranslucentBackground);
-
- }
-
- Second::~Second()
- {
- delete ui;
- }
- void Second::sign_slot()
- {
- this->show();
- }
main.cpp连接界面使用
- #include "widget.h"
- #include "second.h"
- #include
-
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Widget w;
- Second s;
- QObject::connect(&w,&Widget::sign,&s,&Second::sign_slot);
- w.show();
- return a.exec();
- }
第一界面

第二界面
