2024-4-9 QT day3 作业

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::jump_signal,&s,&Second::jump_slot);

    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);
    ui->label_4->setPixmap(QPixmap(":/Logo/ikun.jpg"));
    ui->label_4->setScaledContents(true);
}

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

void Second::jump_slot()
{
    this->show();

}

widget.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);//去掉白框

    //登录按钮信号与槽函数
    connect(this,&Widget::login_signal,this,&Widget::login_slot);

    //取消按钮信号与槽函数
    connect(this,&Widget::cancel_signal,this,&Widget::cancel_slot);

}

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

void Widget::login_slot()
{
    if(ui->lineEdit->text() == "zhangqian" && ui->lineEdit_2->text() == "123456")
    {
        QMessageBox msg (QMessageBox::Information,
                         "Log in",
                         "登录成功!",
                         QMessageBox::Ok
                         );
       int ret = msg.exec();
       if(ret == QMessageBox::Ok)
       {
           this->close();
           emit jump_signal();
       }
     }
     else
       {
         QMessageBox msg (QMessageBox::Critical,
                          "Log in",
                          "账号或密码不匹配,是否重新登录?",
                          QMessageBox::Yes | QMessageBox::No
                           );
         int ret = msg.exec();
         if(ret == QMessageBox::Yes)
         {
            ui->lineEdit_2->clear();
         }
         else if(ret == QMessageBox::No)
         {
            this->close();
         }

       }
}

void Widget::cancel_slot()
{
    QMessageBox msg (QMessageBox::Question,
                     "Log in",
                     "您是否确定要退出登录?",
                     QMessageBox::Yes | QMessageBox::No
                     );
   int ret = msg.exec();
   if(ret == QMessageBox::Yes)
   {
       this->close();
   }
   else if(ret == QMessageBox::No)
   {
       msg.close();
   }
}


void Widget::on_LoginBtn_clicked()
{
    emit login_signal();
}

void Widget::on_CancelBtn_clicked()
{
    emit cancel_signal();
}

 

 

 

 

  • 15
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值