1.思維導圖
2.作業
成果:
第一個頭文件
#ifndef TEST3GET_H
#define TEST3GET_H
#include <QWidget>
#include<QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class test3get; }
QT_END_NAMESPACE
class test3get : public QWidget
{
Q_OBJECT
public:
test3get(QWidget *parent = nullptr);
~test3get();
//聲明信號函數
signals:
void my_signal();
//聲明槽函數
private slots:
void on_pushButton_clicked();
private:
Ui::test3get *ui;
};
#endif // TEST3GET_H
========================================================================
第二個頭文件
#ifndef SENCEND_H
#define SENCEND_H
#include <QWidget>
#include<QPushButton>
namespace Ui {
class sencend;
}
class sencend : public QWidget
{
Q_OBJECT
public:
explicit sencend(QWidget *parent = nullptr);
~sencend();
private:
Ui::sencend *ui;
//聲明信號函數
signals:
void mysignal();
//聲明槽函數
public slots:
void s_slots();
void my_slots();
};
#endif // SENCEND_H
=======================================================================================
第一個實現文件
#include "test3get.h"
#include "ui_test3get.h"
test3get::test3get(QWidget *parent)
: QWidget(parent)
, ui(new Ui::test3get)
{
//關閉畫面頭
this->setWindowFlag(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground);
ui->setupUi(this);
}
test3get::~test3get()
{
delete ui;
}
//建立槽函數
void test3get::on_pushButton_clicked()
{
//判斷用戶名和密碼是否正確
if(ui->username->text()=="addmin"&&ui->password->text()=="123456")
{
//建立一個接收值
int res;
//建立屬性對話框
QMessageBox msg(
//是否有圖標
QMessageBox::NoIcon,
//信息頭
"信息內容",
//信息內容
"登錄成功",
//按鈕
QMessageBox::Ok|QMessageBox::No,
//指定父組件
this
);
//彈出對話框
res=msg.exec();
//點擊判斷是否為ok
if(res==QMessageBox::Ok)
{
//關閉擋墻頁面
this->close();
//并發送一個信號函數讓其他槽函數接收到
emit my_signal();
}
}
else{
//靜態成員對話框
int res=QMessageBox::question(
//父組件
this,
//對話框信息頭
"消息內容",
//對話框信息內容
"用戶名或密碼錯誤",
//按鈕yes/no
QMessageBox::Yes|QMessageBox::No
);
//點擊yes
if(res==QMessageBox::Yes)
{
// 清空username
this->ui->username->clear();
//清空password
this->ui->password->clear();
//點擊no就關閉窗口
}else if(res==QMessageBox::No){
//關閉窗口
this->close();
}
}
}
=======================================================================================
第二個實現文件
#include "sencend.h"
#include "ui_sencend.h"
sencend::sencend(QWidget *parent) :
QWidget(parent),
ui(new Ui::sencend)
{
ui->setupUi(this);
//刪除頁面頭
this->setWindowFlag(Qt::FramelessWindowHint);
}
sencend::~sencend()
{
delete ui;
}
void sencend::s_slots()
{
//生成第二個頁面
this->show();
//點擊exit退出
connect(ui->exit,&QPushButton::clicked,this,&sencend::my_slots);
}
//exit退出
void sencend::my_slots()
{
//關閉sencend頁面
this->close();
}
=======================================================================================
main函數
#include "test3get.h"
#include "sencend.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
test3get w;
w.show();
//建立一個sencend對象
sencend s;
//按鈕實現形成兩個頁面的切換
QObject::connect(&w,&test3get::my_signal,&s,&sencend::s_slots);
return a.exec();
}
=======================================================================================