2024.1.10

发布时间:2024年01月10日

完善对话框,点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示”登录成功“,提供一个Ok按钮,用户点击Ok后,关闭登录界面,跳转到其他界面

如果账号和密码不匹配,弹出错误对话框,给出信息”账号和密码不匹配,是否重新登录“,并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面

如果用户点击取消按钮,则弹出一个问题对话框,给出信息”您是否确定要退出登录?“,并给出两个按钮Yes|No,用户迪纳基Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能

要求:基于属性版和基于静态成员函数版至少各用一个

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowIcon(QIcon(":/Logo/Logo/Hose.jpg"));
    this->setWindowTitle("登录");
    this->setWindowFlag(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
}

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


void Widget::on_pushButton_clicked()
{
    QString user=ui->lineEdit->text();
    QString password=ui->lineEdit_2->text();
    if(user=="111"&&password=="111")
    {
        QMessageBox msg(QMessageBox::Information,
                                 "信息",
                                 "登录成功",
                                 QMessageBox::Ok);
        int ret=msg.exec();
        if(ret==QMessageBox::Ok)
        {
            emit this->my_success();
            this->close();
        }
    }
    else
    {
        QMessageBox msg(QMessageBox::Critical,
                        "错误",
                        "账号和密码不匹配,是否重新登陆",
                        QMessageBox::Yes|QMessageBox::No);
        int ret=msg.exec();
        if(ret==QMessageBox::Yes)
        {
            ui->lineEdit_2->clear();
        }
        else
        {
            this->close();
        }
    }
}

void Widget::on_pushButton_2_clicked()
{
    int ret=QMessageBox::question(this,
                                  "问题",
                                  "你是否确定要退出");
    if(ret==QMessageBox::Yes)
    {
        this->close();
    }
}

文章来源:https://blog.csdn.net/m0_64059184/article/details/135512348
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。