王杰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:
    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->setWindowTitle("cxk");
    this->setWindowIcon(QIcon(":/pictrue/1.jpg"));
    QMovie *mv = new QMovie(":/pictrue/1.gif");
    ui->loclab->setMovie(mv);
    mv->start();
    ui->loclab->setScaledContents(true);

//    ui->usernamelab->setPixmap(QPixmap(":/pictrue/1.jpg"));
//    ui->usernamelab->setScaledContents(true);
//    ui->usernamelab->resize(20,20);



    ui->userEdit->setPlaceholderText("ikun账号");

    ui->passwdedit->setPlaceholderText("ikun密码");
    ui->passwdedit->setEchoMode(QLineEdit::Password);

    //取消按钮
    connect(ui->cancel,SIGNAL(clicked()),this,SLOT(close()));

    //登录按钮
    connect(this,&Widget::my_signal,[&](){
        if(ui->userEdit->text() == "" || ui->passwdedit->text() == "")
        {
            qDebug() << "账号密码输入为空";
        }
        else
        {
            if(ui->userEdit->text() == "admin")
            {
                if(ui->passwdedit->text() == "123456")
                {
                    qDebug() << "登录成功";
                    this->close();
                }
                else
                {
                    qDebug() << "密码错误";
                }
            }
            else
            {
                qDebug() << "账号不存在";
            }
        }
    });
}

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

void Widget::on_login_clicked()
{
    emit my_signal();
}

王杰qtday2_第1张图片

王杰qtday2_第2张图片

你可能感兴趣的:(qt)