2024.9.9

优化登录框:

当用户点击取消按钮,弹出问题对话框,询问是否要确定退出登录,并提供两个按钮,yes|No,如果用户点击的Yes,则关闭对话框,如果用户点击的No,则继续登录

当用户点击的登录按钮,进行账号和密码的匹配,如果匹配成功,则弹出信息对话框,给出信息为,登录成功,并给出一个确定按钮,当用户点击该按钮后,关闭登录界面,弹出另一个界面

当账号和密码不匹配是,给出错误对话框,给出信息为账号和密码不匹配,是否重新登录,并提供两个按钮 Yes|No,如果用户点击了Yes,则清空密码框后,继续登录。如果用户点击的取消,则关闭登录界面

second.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 myslot();
private:
    Ui::Second *ui;
};

#endif // SECOND_H

 widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
public:signals:
    void mysignal();
private slots:
    void on_btn1_clicked();
    void on_btn2_clicked();


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

main.c

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

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

second.cpp

#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::myslot()
{
    this->show();
}

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include <QIcon>
#include <QDebug>
#include <QMessageBox>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setWindowIcon(QIcon(":/pictrue/qq.png"));

    ui->label_3->setPixmap(QPixmap(":/pictrue/logo.png"));
    ui->label_3->setScaledContents(true);

    ui->label->setPixmap(QPixmap(":/pictrue/userName.jpg"));
    ui->label->setScaledContents(true);

    ui->label_2->setPixmap(QPixmap(":/pictrue/passwd.jpg"));
    ui->label_2->setScaledContents(true);

    ui->lineEdit_2->setEchoMode(QLineEdit::Password);

    //connect(this,&Widget::mysignal,this,&Widget::myslots);
}

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


void Widget::on_btn1_clicked()
{
    if(ui->lineEdit->text() == ui->lineEdit_2->text())
    {
        QMessageBox box(QMessageBox::Information,"提示","登陆成功",QMessageBox::Ok,this);
        int res = box.exec();
        if(res == QMessageBox::Ok)
        {
            emit mysignal();
            this->close();
        }
    }
    else
    {
        QMessageBox box(QMessageBox::Information,"提示","账号密码不匹配",QMessageBox::Ok|QMessageBox::No,this);
        int res = box.exec();
        if(res == QMessageBox::Ok)
        {
            ui->lineEdit_2->clear();
        }
        else if(res == QMessageBox::No)
        {
            this->close();
        }
    }
}

void Widget::on_btn2_clicked()
{
    int res = QMessageBox::information(this,"提示","是否要退出",QMessageBox::Yes|QMessageBox::No,QMessageBox::No);
    if(res == QMessageBox::Yes)
    {
        this->close();
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值