12月11日作业

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

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

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

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

second.h

cpp 复制代码
#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:
    void my_slot();

private:
    Ui::second *ui;
};

#endif // SECOND_H

Widget.h

cpp 复制代码
#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();
signals:
    void my_signal();

private slots:
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

main.cpp

cpp 复制代码
#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_signal,&s,&second::my_slot);
    return a.exec();
}

second.cpp

cpp 复制代码
#include "second.h"
#include "ui_second.h"

second::second(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::second)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);//设置纯净窗口
    this->setAttribute(Qt::WA_TranslucentBackground);//将窗口其他部分不显示
}

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

void second::my_slot()
{
    this->show();
}

Widget.cpp

cpp 复制代码
#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(":/Logo/qq.jpg"));  //设置软件图标
}

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

void Widget::on_pushButton_clicked()
{
    //当账号行编辑器内容和密码行编辑器内容都匹配时,登陆成功,否则失败
    if(ui->lineEdit->text() == "114514" && ui->lineEdit_2->text() == "1919810")
    {
        //基于属性版对话框,信息对话框,只显示Ok按钮
        QMessageBox msg(
                    QMessageBox::Information,"登录","登录成功",QMessageBox::Ok,this);
        int ret = msg.exec();  //exec弹出对话框
        if(ret == QMessageBox::Ok)
        {
            emit my_signal();   //发出自定义信号
            this->close();      //关闭窗口
        }
    }
    else
    {
        //基于静态成员函数版对话框,生成两个按钮
        int ret = QMessageBox::question(this,"错误","账号和密码不匹配,是否重新登录?"
                                        ,QMessageBox::Yes | QMessageBox::No);
        if(ret == QMessageBox::Yes)
        {
            ui->lineEdit_2->clear();   //将密码行编辑器内容清空
        }
        else if(ret == QMessageBox::No)
        {
            this->close();     //关闭窗口
        }
    }
}

void Widget::on_pushButton_2_clicked()
{
    //基于静态成员函数版对话框,生成两个按钮
    int ret = QMessageBox::question(this,"退出","您是否确认要退出登录?",
                                    QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes)
    {
        this->close();  //关闭窗口
    }
}

思维导图

相关推荐
yolo_guo12 小时前
opencv 学习: QA_01 什么是图像锐化
linux·c++·opencv·计算机视觉
_OP_CHEN12 小时前
算法基础篇:(六)基础算法之双指针 —— 从暴力到高效的优化艺术
c++·算法·acm·优化算法·双指针·oj题·算法蓝桥杯
laplace012312 小时前
PyQt5 + Qt Designer配置指令
开发语言·qt
oioihoii13 小时前
C++中有双向映射数据结构吗?Key和Value能否双向查找?
数据结构·c++·算法
_OP_CHEN13 小时前
算法基础篇:(八)贪心算法之简单贪心:从直觉到逻辑的实战指南
c++·算法·贪心算法·蓝桥杯·算法竞赛·acm/icpc·简单贪心
小欣加油13 小时前
leetcode 2536 子矩阵元素加1
数据结构·c++·算法·leetcode·矩阵
月半流苏13 小时前
Problem: lab-week10-exercise02 Building a Fiber Network
c++·算法·并查集
温宇飞13 小时前
计算机语言中的多态实现
c++
小龙报14 小时前
《VScode搭建教程(附安装包)--- 开启你的编程之旅》
c语言·c++·ide·vscode·单片机·物联网·编辑器
kyle~14 小时前
C++20--- concept 关键字 为模板参数提供了编译期可验证的约束机制
运维·c++