• QT day3


    #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
        setWindowIcon(QIcon(":/pictures/q3.png"));
        setWindowTitle("QQ登录");
        setWindowFlag(Qt::FramelessWindowHint);
    
        // 使用手动连接,将取消按钮使用qt4版本的连接到自定义的槽函数中
        connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(my_slot()));
    
        // 使用qt5版本手动连结
        connect(ui->loginButton, &QPushButton::clicked, this, &Widget::my_login_slot);
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    // 登录对应的槽函数
    void Widget::my_login_slot()
    {
        // 点击登录对话框,如果账号和密码匹配,则弹出信息对话框,给出提示登录成功,提供一个Ok按钮,
        // 用户点击OK后,关闭登录界面,跳转到其他界面
        if (ui->userNameLineEdit->text() == "admin" && ui->passWdLineEdit->text() == "123456")
        {
            // 基于属性版
            QMessageBox login(QMessageBox::Information, "登录对话框", "登陆成功", QMessageBox::Ok, this);
            login.exec(); // 属性版需要exec函数弹出信息对话框
    
            emit my_jump();
    
            this->close();
        }
        // 如果账号和密码不匹配,弹出错误对话框,给出信息"账号和密码不匹配,是否重新登录"并提供两个按钮Yes|lNo
        //用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面
        else
        {
            // 基于静态成员函数版
            int ret = QMessageBox::critical(this, "错误对话框", "账号和密码不匹配,是否重新输入", QMessageBox::Yes
                                            | QMessageBox::No);
            switch(ret)
            {
            case QMessageBox::Yes: ui->passWdLineEdit->clear(); break;
            case QMessageBox::No: this->close(); break;
            }
        }
    
    
    }
    
    // 取消对应的槽函数
    // 用户点击取消按钮,则弹出一个问题对话框,给出信息"您是否确定要退出登录?",并给出两个按钮Yes|No
    // 用户点击Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
    void Widget::my_slot()
    {
        int ret = QMessageBox::question(this, "问题对话框", "您是否确定要退出登录?", QMessageBox::Yes | QMessageBox::No);
        if (ret == QMessageBox::Yes)
        {
            this->close();
        }
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70

    思维导图
    在这里插入图片描述

  • 相关阅读:
    Spring中的BeanFactory和ApplicationContext的区别
    Three.js 与 Python 语法 (PyWeb3D)
    数据结构与算法(java版)第二季 - 7 图 BFS DFS 拓扑排序
    docker.5-Docker容器化部署企业级应用集群
    Educational Codeforces Round 138 (Rated for Div. 2) A-E
    【0108】checkpoint运行原理
    docker部署mysql主从备份
    微服务项目:尚融宝(48)(核心业务流程:借款 审核(3))
    C/C++数据结构——QQ帐户的申请与登陆(散列表)
    非关系型数据库之Redis【Jedis客户端+Jedis连接集群】
  • 原文地址:https://blog.csdn.net/m0_51235177/article/details/134428673