完善對話框,點擊登錄對話框,如果賬號和密碼匹配,則彈出信息對話框,給出提示”登錄成功“,提供一個Ok按鈕,用戶點擊Ok后,關閉登錄界面,跳轉到其他界面
如果賬號和密碼不匹配,彈出錯誤對話框,給出信息”賬號和密碼不匹配,是否重新登錄“,并提供兩個按鈕Yes|No,用戶點擊Yes后,清除密碼框中的內容,繼續讓用戶進行登錄,如果用戶點擊No按鈕,則直接關閉登錄界面
如果用戶點擊取消按鈕,則彈出一個問題對話框,給出信息”您是否確定要退出登錄?“,并給出兩個按鈕Yes|No,用戶迪納基Yes后,關閉登錄界面,用戶點擊No后,關閉對話框,繼續執行登錄功能
要求:基于屬性版和基于靜態成員函數版至少各用一個
widget.h
#ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QMessageBox>QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACEclass Widget : public QWidget {Q_OBJECTpublic:Widget(QWidget *parent = nullptr);~Widget(); signals:void my_jump();private slots:void on_pushButton_clicked();void on_pushButton2_clicked();private:Ui::Widget *ui; }; #endif // WIDGET_H
main.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_jump,&s,&Second::jump_slot);return a.exec();
}
wdiget.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/Logo/qq.png"));}Widget::~Widget()
{delete ui;
}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked()
{//靜態成員函數版本//判斷用戶名和密碼輸入是否正確if(ui->userEdit->text() == "admin" && ui->passwordEdit->text() == "123456"){//跳出信息對話框,設置Ok按鈕int ret = QMessageBox::information(this,"信息對話框","登陸成功",QMessageBox::Ok);//如果點擊Ok,就觸發跳轉頁面事件,并關閉登錄頁面if(ret == QMessageBox::Ok){emit my_jump();this->close();}}else{//當用戶名或者密碼輸入錯誤時,跳出問題對話框,設置Yes和No按鈕int ret = QMessageBox::critical(this,"錯誤對話框","賬號和密碼不匹配,是否重新登陸",QMessageBox::Yes | QMessageBox::No);//如果點擊Yes,清空密碼if(ret == QMessageBox::Yes){ui->passwordEdit->clear();}//如果點擊No,關閉登錄頁面else if(ret == QMessageBox::No){this->close();}}void Widget::on_pushButton2_clicked()
{QMessageBox msg(QMessageBox::Question,"問題對話框","您是否確定要退出登錄",QMessageBox::Yes | QMessageBox::No);//點擊Yes,關閉登陸頁面int ret = msg.exec();if(ret == QMessageBox::Yes){this->close();}
}