作业--day44

完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面。如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面。如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户迪纳基Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能。要求:基于属性版和基于静态成员函数版至少各用一个

主函数

#include "work2.h"
#include "success.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Work2 w;
    w.show();

    Success s;
    QObject::connect(&w, &Work2::WtoSsignal, &s, &Success::SuccessSlots);

    return a.exec();
}

第一个界面

#include "work2.h"
#include "ui_work2.h"

Work2::Work2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Work2)
{
    ui->setupUi(this);
    this->setFixedSize(this->width(), this->height());
    this->setWindowFlag(Qt::FramelessWindowHint);

    //上部logo
    QMovie *mv = new QMovie(":/pictrue/qq2.gif");
    ui->log_lab->setMovie(mv);
    mv->start();

    //输入框设置
    ui->account_line->setStyleSheet("background-color:white; border-radius:5px;");
    ui->pwd_line->setStyleSheet("background-color:white; border-radius:5px;");

    //按钮设置
    ui->login_btn->setStyleSheet("background-color:white; border-radius:10px;");
    ui->cancel_btn->setStyleSheet("background-color:white; border-radius:10px;");

    //基于qt4版本的connect
    connect(ui->cancel_btn, SIGNAL(clicked()), this, SLOT(cancel_slots()));
    //基于qt5版本的connect
    connect(ui->login_btn, &QPushButton::clicked, this, &Work2::login_slots);

}

Work2::~Work2()
{
    delete ui;
}

//登录的槽
void Work2::login_slots()
{
    if(ui->account_line->text() == "admin" && ui->pwd_line->text() == "123456"){
        QMessageBox *msg_success = new QMessageBox(QMessageBox::Information,
                                           "登录成功",
                                           "点击跳转",
                                           QMessageBox::Ok,
                                           this);
        int res = msg_success->exec();
        if(res == QMessageBox::Ok){
            //发送信号
            emit WtoSsignal();
            this->close();
        }

    }else{
        int res = QMessageBox::critical(this,
                              "登录失败",
                              "账号和密码不匹配,是否重新登录",
                              QMessageBox::Yes | QMessageBox::No);
        if(res == QMessageBox::Yes){
            ui->pwd_line->clear();
        }else{
            this->close();
        }

    }
}

//取消的槽
void Work2::cancel_slots()
{
    int res = QMessageBox::question(this,
                                    "退出",
                                    "您是否确定要退出登录?",
                                    QMessageBox::Yes | QMessageBox::No);
    if(res == QMessageBox::Yes){
        this->close();
    }

}

第二个界面

#include "success.h"
#include "ui_success.h"

Success::Success(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Success)
{
    ui->setupUi(this);
    QMovie *mv = new QMovie(":/pictrue/car.gif");
    ui->label->setMovie(mv);
    mv->start();

    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
}

Success::~Success()
{
    delete ui;
}

void Success::on_pushButton_clicked()
{
    this->close();
}

void Success::SuccessSlots()
{
    this->show();
}

作业--day44_第1张图片
作业--day44_第2张图片
作业--day44_第3张图片

思维导图

你可能感兴趣的:(c++)