10_18Qt

头文件

#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:
    void my_signal();
private slots:
    void on_login_clicked();

private:
    Ui::Widget *ui;
};
#endif // WIDGET_H

源文件

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

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

    this->setWindowFlag(Qt::FramelessWindowHint);

    ui->logoLab->setPixmap(QPixmap(":/res/1.gif"));
    QMovie *mv =  new QMovie(":/res/1.gif");
    ui->logoLab->setMovie(mv);
    mv->start();
    ui->logoLab->setScaledContents(true);

    ui->userLab->resize(40,40);
    ui->userLab->setPixmap(QPixmap(":/res/preview.gif"));
    ui->userLab->setScaledContents(true);

    ui->passLab->resize(40,40);
    ui->passLab->setPixmap(QPixmap(":/res/preview.gif"));
    ui->passLab->setScaledContents(true);

    ui->userEdit->setPlaceholderText("请输入账号");
    ui->passEdit->setPlaceholderText("请输入密码");
    ui->passEdit->setEchoMode(QLineEdit::Password);

    ui->login->setIcon(QIcon(":/res/preview.gif"));
    ui->cancel->setIcon(QIcon(":/res/preview.gif"));

    connect(ui->cancel,SIGNAL(clicked()),this,SLOT(close()));

    connect(this,&Widget::my_signal,[&](){
        if(ui->userEdit->text()=="" || ui->passEdit->text()=="")
        {
            qDebug() << "账号或密码为空";
        }else{
            if(ui->userEdit->text()=="admin")
            {
                if(ui->passEdit->text()=="123456")
                {
                    qDebug() << "登录成功";
                    this->close();
                }else
                {
                    qDebug() << "密码错误,请重新输入";
                    ui->passEdit->clear();
                }
            }else{
                qDebug() << "账号不存在";
            }
        }
    });
}
Widget::~Widget()
{
    delete ui;
}
void Widget::on_login_clicked()
{
    emit my_signal();
}

思维导图

10_18Qt_第1张图片

你可能感兴趣的:(qt)