QTday3

#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("请尝试登录>_<");
    ui->name->setPlaceholderText("请输入用户名/账号/邮箱");
    ui->password->setPlaceholderText("请输入密码");
    ui->password->setEchoMode(QLineEdit::Password);//密码不可见
    this->connect(ui->btn2,SIGNAL(clicked()),this,SLOT(on_btn2()));//qt4退出
    connect(ui->btn1,&QPushButton::clicked,this,&Widget::on_btn1);//qt5登录
}

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


void Widget::on_btn1()
{

    if(ui->name->text()=="admin" && ui->password->text()=="123456")
    {
        QMessageBox msg(
                    QMessageBox::Information,//图标
                    "提示",//对话框标题
                    "登录成功",//对话框文本
                    QMessageBox::Ok,//提供按钮
                    this);//父对象
        int ret = msg.exec();//exec()函数执行对话框
        if(ret == QMessageBox::Ok)//按钮判断
        {
            this->close();
            emit jump();
        }
    }
    else
    {
        QMessageBox msg1(
                    QMessageBox::Information,
                    "提示",
                    "账号与信息不符,是否重新登录",
                    QMessageBox::Yes | QMessageBox::No,
                    this);
        int ret1 = msg1.exec();
        if(ret1 == QMessageBox::Yes)
        {
            ui->password->clear();
        }
        else if(ret1 == QMessageBox::No)
        {
             this->close();
        }
    }
}

void Widget::on_btn2()
{//静态成员函数调用
    int ret2 = QMessageBox::question(this,
                "提示",
                "你是否要退出登录",
                QMessageBox::Yes | QMessageBox::No);

    if(ret2 == QMessageBox::Yes)
    {
         this->close();
    }
}
#ifndef WIDGET_H
#define WIDGET_H

#include 
#include 
#include 
#include 

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
signals://信号函数
    void jump();

public slots://公共的槽函数


private slots:
    void on_btn1();

    void on_btn2();


private:
    Ui::Widget *ui;

    QPushButton *btn1;
    QPushButton *btn2;
};
#endif // WIDGET_H
#include "form.h"
#include "ui_form.h"

Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
{
    ui->setupUi(this);
}

Form::~Form()
{
    delete ui;
}
void Form::jumpSlot()
{
    this->show();
}
#ifndef FORM_H
#define FORM_H

#include 

namespace Ui {
class Form;
}

class Form : public QWidget
{
    Q_OBJECT

public:
    explicit Form(QWidget *parent = nullptr);
    ~Form();
public slots:
    void jumpSlot();
private:
    Ui::Form *ui;
};

#endif // FORM_H

QTday3_第1张图片QTday3_第2张图片QTday3_第3张图片

你可能感兴趣的:(c++)