day5-QT

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include<QFontDialog> //字体对话框类
#include<QFont> //字体类
#include<QMessageBox> //消息对话框类
#include<QColorDialog> //颜色对话框类
#include<QColor> //颜色类
#include<QFileDialog> //文件对话框类
#include<QDebug>
#include<QFile>

QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

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

signals:
    void jump_signal();
private slots:
    void on_Login_clicked();

    void on_Cancel_clicked();

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

success.h

#ifndef SUCCESS_H
#define SUCCESS_H

#include <QWidget>

namespace Ui {
class Success;
}

class Success : public QWidget
{
    Q_OBJECT

public:
    explicit Success(QWidget *parent = nullptr);
    ~Success();
public slots:
    void success_slot();
private:
    Ui::Success *ui;
};

#endif // SUCCESS_H

widget.cpp

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

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

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

void Widget::on_Login_clicked()
{
    QString user=ui->User->text();
    QString passwd=ui->Passwd->text();
    if(user == "admin" && passwd == "123456")
    {
        QMessageBox msg_ls(QMessageBox::Information," ","登陆成功!",QMessageBox::Yes,this);
        msg_ls.exec();
        this->close();
        emit jump_signal();
    }
    else
    {
        QMessageBox msg_lf(QMessageBox::Information," ","账号和密码不匹配,是否重新登录",QMessageBox::Yes|QMessageBox::No,this);
        int ret = msg_lf.exec();
        if(ret == QMessageBox::Yes)
        {
            ui->User->clear();
            ui->Passwd->clear();
        }
        else
        {
           this->close();
        }

    }
}


void Widget::on_Cancel_clicked()
{
    int ret = QMessageBox::question(this, " ","您是否确定要退出登录?", QMessageBox::Yes | QMessageBox::No);
    if(ret == QMessageBox::Yes)
    {
        this->close();
    }
}

success.cpp

#include "success.h"
#include "ui_success.h"

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

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

void Success::success_slot()
{
    this->show();
}

main.cpp

#include "widget.h"
#include "success.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    Success s;
    QObject::connect(&w,&Widget::jump_signal,&s,&Success::success_slot);
    return a.exec();
}

结果:

​​​​​​​

​​​​​​​

相关推荐

  1. <span style='color:red;'>QT</span> <span style='color:red;'>day</span><span style='color:red;'>5</span>

    QT day5

    2024-03-27 21:00:03      55 阅读
  2. <span style='color:red;'>QT</span> <span style='color:red;'>day</span><span style='color:red;'>5</span>

    QT day5

    2024-03-27 21:00:03      31 阅读
  3. <span style='color:red;'>day</span><span style='color:red;'>5</span>-<span style='color:red;'>QT</span>

    day5-QT

    2024-03-27 21:00:03      30 阅读
  4. <span style='color:red;'>day</span><span style='color:red;'>5</span> <span style='color:red;'>qt</span>

    day5 qt

    2024-03-27 21:00:03      37 阅读

最近更新

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

    2024-03-27 21:00:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 21:00:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 21:00:03       82 阅读
  4. Python语言-面向对象

    2024-03-27 21:00:03       91 阅读

热门阅读

  1. reactive和ref的异同、toRef和toRefs的使用

    2024-03-27 21:00:03       34 阅读
  2. Unity运行中加载特效AB包并且对象池管理

    2024-03-27 21:00:03       36 阅读
  3. 自动化测试理论基础(超详细)

    2024-03-27 21:00:03       40 阅读
  4. 态势感知平台简单介绍

    2024-03-27 21:00:03       42 阅读
  5. ChatGPT编程实践指南:让AI成为你的代码良师

    2024-03-27 21:00:03       38 阅读