12.11

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

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

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

头文件

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMessageBox>
#include <QDebug>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    //第一个界面自定义信号
signals:
    void my_jump();

private slots:
    void on_pushButton_clicked();

    void on_Btn2_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
#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();

    //第二个界面槽函数声明
public slots:
    void jump_slot();

private:
    Ui::Second *ui;
};

#endif // SECOND_H

源文件

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

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);//去掉头部
    this->setAttribute(Qt::WA_TranslucentBackground);//去掉窗口剩余部分
    this->setWindowIcon(QIcon(":/pictrue/qq.png"));//设置图标
}

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

//登录按钮对应的槽函数处理
void Widget::on_pushButton_clicked()
{
    //判断登录是否成功
    if(ui->userNameEdit->text() == "admin" && ui->passwdEdit->text() == "123456")
    {
        //信息对话框  基于静态函数版本
        int ret = QMessageBox::information(this,"信息","登录成功",QMessageBox::Yes);
        if(ret == QMessageBox::Yes)
        {
            emit my_jump();//触发信号
            this->close();//关闭第一个界面
        }

    }else
    {
        //错误对话框    基于属性版本
        QMessageBox msg(QMessageBox::Critical,"错误","账号和密码不匹配,是否重新登陆",QMessageBox::Yes | QMessageBox::No,this);
        int ret = msg.exec();//弹出对话框
        if(ret == QMessageBox::Yes)
        {
            ui->passwdEdit->clear();//清空密码
        }else if(ret == QMessageBox::No)
        {
            this->close();//关闭页面
        }
    }
}
//取消按钮对应的槽函数处理
void Widget::on_Btn2_clicked()
{
    //问题对话框  基于静态函数版本
    int ret = QMessageBox::question(this,"问题","您是否确定要退出登录?",QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes)
    {
        this->close();//关闭登录页面
    }
}
#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();
}

相关推荐

  1. 1213

    2023-12-11 21:38:02       75 阅读
  2. AcWing 1211. 蚂蚁感冒

    2023-12-11 21:38:02       43 阅读
  3. test<span style='color:red;'>1111</span>

    test1111

    2023-12-11 21:38:02      64 阅读
  4. 超市<span style='color:red;'>111</span>

    超市111

    2023-12-11 21:38:02      21 阅读
  5. xtu oj 1271 color

    2023-12-11 21:38:02       53 阅读
  6. 【LeetCode】1251. 平均售价

    2023-12-11 21:38:02       53 阅读
  7. 1291. Sequential Digits

    2023-12-11 21:38:02       54 阅读
  8. SF相关1111

    2023-12-11 21:38:02       66 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-11 21:38:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-11 21:38:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-11 21:38:02       82 阅读
  4. Python语言-面向对象

    2023-12-11 21:38:02       91 阅读

热门阅读

  1. bz2 --- 对 bzip2 压缩算法的支持

    2023-12-11 21:38:02       55 阅读
  2. go进阶语法10问

    2023-12-11 21:38:02       59 阅读
  3. 含电热联合系统的微电网运行优化附Matlab代码

    2023-12-11 21:38:02       55 阅读
  4. Holynix

    Holynix

    2023-12-11 21:38:02      49 阅读
  5. PKCS#11及其在车联网中的应用

    2023-12-11 21:38:02       57 阅读
  6. 用keepalived做mysql高可用

    2023-12-11 21:38:02       58 阅读
  7. 使用can_require函数的测试程序

    2023-12-11 21:38:02       49 阅读