day3 QT

作业

day3 QT_第1张图片
原页面 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);
}

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


void Widget::on_pushButton_clicked()
{
    if(ui->lineEdit->text() == "admin" && ui->lineEdit_2->text() == "123456")
    {
        //成功对话框
        QMessageBox msg(QMessageBox::Information,"登录提示","登录成功",QMessageBox::Ok);
        int rec = msg.exec();

        if(rec == QMessageBox::Ok)
        {
            this->close();
            emit goto_main();
        }
    }
    else // 失败对话框
    {
        QMessageBox msg1(QMessageBox::Critical,"登录提示","账号和密码不匹配,是否重新登陆",QMessageBox::Yes | QMessageBox::No);
        int rec = msg1.exec();

        if(rec == QMessageBox::Yes)
        {
            ui->lineEdit->clear();
            ui->lineEdit_2->clear();
            msg1.close();


        }
        else
        {
            msg1.close();
            this->close();
        }
    }

}

void Widget::on_pushButton_2_clicked()
{
    QMessageBox msg2(QMessageBox::Critical,"取消提示","您是否确定要退出登录?",QMessageBox::Yes | QMessageBox::No);
    int rec = msg2.exec();

    if(rec == QMessageBox::Yes)
    {

        msg2.close();
        this->close();
    }
    else
    {
        msg2.close();
    }
}

main.cpp

#include "widget.h"
#include "main_interface.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    main_interface mf;
    QObject::connect(&w,&Widget::goto_main,&mf,&main_interface::new_page);
    return a.exec();
}

你可能感兴趣的:(qt,命令模式,开发语言)