如果账号和密码不匹配,弹出错误对话框,给出信息"账号和密码不匹配,是否重新登录",并提供两个按钮Yes|No,用户点击Yes后,清除密码框中的内容,继续让用户进行登录,如果用户点击No按钮,则直接关闭登录界面如果用户点击取消按钮,则弹出一个问题对话框,给出信息"您是否确定要退出登录?",并给出两个按钮Yes|INo,用户点击Yes后,关闭登录界面,用户点击No后,关闭对话框,继续执行登录功能
QT61.h
cpp
#ifndef QT61_H
#define QT61_H
#include <QWidget>
namespace Ui {
class QT61;
}
class QT61 : public QWidget
{
Q_OBJECT
public:
explicit QT61(QWidget *parent = nullptr);
~QT61();
public slots:
void fun();
private:
Ui::QT61 *ui;
};
#endif // QT61_H
wihget.h
cpp
#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
signals:
void my_signal();
public:
Widget(QWidget *parent = nullptr);
~Widget();
private slots:
void on_btn1_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
QT61.cpp
cpp
#include "qt61.h"
#include "ui_qt61.h"
QT61::QT61(QWidget *parent) :
QWidget(parent),
ui(new Ui::QT61)
{
ui->setupUi(this);
}
QT61::~QT61()
{
delete ui;
}
void QT61::fun()
{
this->show();
}
wihget.cpp
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_btn1_clicked()
{
if(ui->lineEdit->text()=="12345" && ui->lineEdit_2->text()=="12345");
{
QMessageBox msg(QMessageBox::Question,
"提示",
"登陆成功",
QMessageBox::Yes
);
int res =msg.exec();
if(res==QMessageBox::Yes)
{
emit my_signal();
this->close();
}
}
if(ui->lineEdit->text()!="12345" | ui->lineEdit_2->text()!="12345")
{
QMessageBox msg(QMessageBox::Question,
"提示",
"登陆失败,是否重新登陆",
QMessageBox::Yes| QMessageBox::No
);
int sun=msg.exec();
if(sun==QMessageBox::Yes)
{
this->show();
ui->lineEdit_2->clear();
}
else if(sun==QMessageBox::No)
{
this->close();
}
}
}
main.cpp
cpp
#include "widget.h"
#include "qt61.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
QT61 q;
QObject::connect(&w,&Widget::my_signal,&q,&QT61::fun);
w.show();
return a.exec();
}