12月11日作业

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

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

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

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

第一个头文件

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_btn_log_clicked();

    void on_btn_cancle_clicked();

private:
    Ui::Widget *ui;
signals:
    void my_jump();  //第一个界面的自定义信号

};
#endif // WIDGET_H

第一个源文件

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);

    this->setWindowIcon(QIcon(":/pictrue/kunkun.webp"));
}

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


void Widget::on_btn_log_clicked()  //登录按钮槽函数
{
    //静态成员函数版本
    if(ui->edit_id->text() == "admin" & ui->edit_passward->text() == "123456")
    {
        int ret = QMessageBox::information(this,
                                           "登陆成功",
                                           "确认登录");

        if(ret == QMessageBox::Ok)
        {
            //跳转到其他界面
            emit my_jump();  //触发自定义信号
            //关闭当前界面
            this->close();
        }
    }
    else  //登录失败
    {
        //静态成员函数版本
        int ret = QMessageBox::critical(this,
                                        "登录失败",
                                        "账号和密码不匹配,是否重新登录",
                                        QMessageBox::Yes | QMessageBox::No);

        if(ret == QMessageBox::Yes)
        {
            //清空密码,重新登录
            ui->edit_passward->clear();
        }
        else if(ret == QMessageBox::No)
        {
            //直接关闭
            this->close();
        }
    }
}

void Widget::on_btn_cancle_clicked()  //取消按钮槽函数
{
    //基于属性版本
    QMessageBox msg(QMessageBox::Question,
                    "取消",
                    "您是否确定要取消登录?",
                    QMessageBox::Yes | QMessageBox::No,
                    this);
    //调用exec函数
    int ret = msg.exec();
    if(ret == QMessageBox::Yes)
    {
        this->close();
    }
}

第二个头文件

#ifndef SECOND_H
#define SECOND_H

#include <QWidget>

namespace Ui {
class Second ;
}

class Second : public QWidget
{
    Q_OBJECT

public:
    explicit Second(QWidget *parent = nullptr);
    ~Second();

private:
    Ui::Second *ui;

public slots:
    void jump_slot();  //自定义的槽函数说明
};

#endif // SECOND_H

第二个源文件

#include "second.h"
#include "ui_second.h"

Second::Second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Second)
{
    ui->setupUi(this);
}

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

//自定义槽函数实现
void Second::jump_slot()
{
    this->show();  //第二个界面显示
}

主函数

#include "widget.h"
#include "second.h"

#include <QApplication>

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

    Second s;  //实例化第二个界面
    QObject::connect(&w,&Widget::my_jump,&s,&Second::jump_slot);
    return a.exec();
}

ui文件

效果演示

君子声明

相关推荐

  1. 1211总结

    2023-12-11 22:06:03       43 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-11 22:06:03       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-11 22:06:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-11 22:06:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-11 22:06:03       18 阅读

热门阅读

  1. Python数据分析的模块有哪些?

    2023-12-11 22:06:03       36 阅读
  2. 数据结构和算法专题---2、算法思想

    2023-12-11 22:06:03       37 阅读
  3. vue3中修改element plus 主题色

    2023-12-11 22:06:03       38 阅读
  4. vue 基础

    2023-12-11 22:06:03       34 阅读
  5. qt有哪些常用控件

    2023-12-11 22:06:03       35 阅读
  6. 传染病传播速度

    2023-12-11 22:06:03       34 阅读
  7. C语言-链表_基础

    2023-12-11 22:06:03       26 阅读
  8. redis中scan命令详解

    2023-12-11 22:06:03       30 阅读
  9. Redisson的基础使用(2)

    2023-12-11 22:06:03       38 阅读
  10. 【GO】记一次排查 docker virtual size 过大问题

    2023-12-11 22:06:03       38 阅读
  11. 12.11

    12.11

    2023-12-11 22:06:03      41 阅读