2023/12/11 作业

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();
}
=======================================================================================
  • 20
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值