QTday2

#ifndef WIDGET_H
#define WIDGET_H

#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://信号函数

public slots://公共的槽函数


private slots:
    void on_btn1_clicked();

    void on_btn2_clicked();


private:
    Ui::Widget *ui;

    QPushButton *btn1;
    QPushButton *btn2;
};
#endif // WIDGET_H
#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_clicked()));//qt4退出
    connect(ui->btn1,&QPushButton::clicked,this,&Widget::on_btn1_clicked);//qt5登录
}

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


void Widget::on_btn1_clicked()
{

    if(ui->name->text()=="admin" && ui->password->text()=="123456")
    {
        qDebug()<<"登录成功";
        this->close();
    }
    else
    {
        qDebug()<<"登录失败";
        ui->password->clear();
    }
}

void Widget::on_btn2_clicked()
{
    this->close();
}

QTday2_第1张图片QTday2_第2张图片

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