• Qt10-19


    第一个界面的头文件

    #ifndef WIDGET_H
    #define WIDGET_H
    
    #include 
    #include//动态图片所用的类
    #include//消息对话框类
    
    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();//自定义信号
        void jump();//跳转信号
    public slots:
        void on_login_clicked();//响应自定义信号的槽函数
        void jump2Slot();//接收第二个界面的槽函数
    
    private slots:
        void on_cancel_clicked();//点击cancel按钮的槽函数
    
    private:
        Ui::Widget *ui;
    };
    #endif // WIDGET_H
    
    • 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

    第二个界面的头文件

    #ifndef SECOND_H
    #define SECOND_H
    
    #include 
    
    namespace Ui {
    class Second;
    }
    
    class Second : public QWidget
    {
        Q_OBJECT
    public slots:
        void jumpSlot();//接收登录界面的槽函数
    public:
        explicit Second(QWidget *parent = nullptr);//有参构造
        ~Second();//析构函数
    signals:
        void jump2();//跳转回登录界面的信号
    private slots:
        void on_pb5_clicked();//点击按钮触发jump2
    
    private:
        Ui::Second *ui;
    };
    
    #endif // SECOND_H
    
    
    • 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

    main函数

    #include "widget.h"
    #include "second.h"
    #include 
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        Widget w;
        w.show();
        Second s;//实例化第二个界面的对象
        QObject::connect(&w,&Widget::jump,&s,&Second::jumpSlot);//连接jump和jumpSlot函数
        QObject::connect(&s,&Second::jump2,&w,&Widget::jump2Slot);//连接jump2和jumpSlot2函数
        return a.exec();
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    第一个界面的源文件

    #include "widget.h"
    #include "ui_widget.h"
    
    Widget::Widget(QWidget *parent)
        : QWidget(parent)
        , ui(new Ui::Widget)
    {
        ui->setupUi(this);
    
        this->setWindowFlag(Qt::FramelessWindowHint);
    
        ui->logoLab->setPixmap(QPixmap(":/res/1.gif"));
        QMovie *mv =  new QMovie(":/res/1.gif");
        ui->logoLab->setMovie(mv);
        mv->start();
        ui->logoLab->setScaledContents(true);
    
        ui->userLab->resize(40,40);
        ui->userLab->setPixmap(QPixmap(":/res/preview.gif"));
        ui->userLab->setScaledContents(true);
    
        ui->passLab->resize(40,40);
        ui->passLab->setPixmap(QPixmap(":/res/preview.gif"));
        ui->passLab->setScaledContents(true);
    
        ui->userEdit->setPlaceholderText("请输入账号");
        ui->passEdit->setPlaceholderText("请输入密码");
        ui->passEdit->setEchoMode(QLineEdit::Password);
    
        ui->login->setIcon(QIcon(":/res/preview.gif"));
        ui->cancel->setIcon(QIcon(":/res/preview.gif"));
    
        connect(this,&Widget::my_signal,[&](){//连接自定义信号与自定义槽函数,判断账号密码是否正确,并进行跳转
            if(ui->userEdit->text()=="" || ui->passEdit->text()=="")
            {
                QMessageBox::information(this,"提示","账号或密码为空");//信息提示对话框
            }else{
                if(ui->userEdit->text()=="admin")
                {
                    if(ui->passEdit->text()=="123456")
                    {
                        ui->userEdit->clear();
                        ui->passEdit->clear();
                        QMessageBox::information(this,"提示","登录成功");
                        this->close();
                        emit jump();
                    }else
                    {
                        int ret = QMessageBox::critical(this,"错误","账号和密码不匹配,是否重新登录",QMessageBox::Yes|QMessageBox::No);
                           //错误信息对话框
                       if(ret==QMessageBox::Yes)
                       {
                           ui->passEdit->clear();
                       }else{
                           this->close();
                       }
                    }
                }else{
                    QMessageBox::information(this,"提示","账号不存在",QMessageBox::Yes|QMessageBox::No);
                }
            }
        });
    
    
    }
    
    Widget::~Widget()
    {
        delete ui;
    }
    
    void Widget::on_login_clicked()
    {
        emit my_signal();
    }
    
    void Widget::jump2Slot()
    {
        this->show();
    }
    
    void Widget::on_cancel_clicked()
    {
        //实例化对象实现消息对话框
         QMessageBox msg(QMessageBox::Information,"提示","您是否要退出登录?",QMessageBox::Yes|QMessageBox::No,this);
         int ret = msg.exec();
      //  int ret = QMessageBox::question(this,"问题","您是否要退出登录?",QMessageBox::Yes|QMessageBox::No);
        if(ret == QMessageBox::Yes)
        {
            this->close();
        }else{
            this->show();
        }
    }
    
    • 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
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94

    第二个界面的源文件

    #include "second.h"
    #include "ui_second.h"
    
    void Second::jumpSlot()
    {
        this->show();
    }
    
    Second::Second(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Second)
    {
        ui->setupUi(this);
    
        this->setWindowTitle("马化腾之泪");
        this->setWindowIcon(QIcon(":/res/preview.gif"));
    }
    
    Second::~Second()
    {
        delete ui;
    }
    
    void Second::on_pb5_clicked()
    {
        emit jump2();
        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

    Xmind

    在这里插入图片描述

  • 相关阅读:
    Java程序设计2023-第三次上机练习
    迭代器和生成器
    JWFD开源工作流-随机函数发生器最新进展
    Crypto(2)攻防世界-幂数加密
    OpenHarmony语言基础类库【@ohos.url (URL字符串解析)】
    4款实用的黑科技软件,白嫖党最爱,功能强大到离谱
    飞桨模型部署至docker并使用FastAPI调用(三)-API部署
    傅里叶特征学习高频:Fourier 相关工作+实验分析+代码实现
    网络传输 Tips 小记
    vue 学习
  • 原文地址:https://blog.csdn.net/qq_45910739/article/details/133932729