使用手动连接,将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中,在自定义的槽函数中调用关闭函数,将登录按钮使用qt5版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出"登录失败",并将密码框中的内容清空。
#include "work2.h"
#include "ui_work2.h"
Work2::Work2(QWidget *parent) :
QWidget(parent),
ui(new Ui::Work2)
{
ui->setupUi(this);
this->setFixedSize(this->width(), this->height());
this->setWindowFlag(Qt::FramelessWindowHint);
//上部logo
QMovie *mv = new QMovie(":/pictrue/qq2.gif");
ui->log_lab->setMovie(mv);
mv->start();
//输入框设置
ui->account_line->setStyleSheet("background-color:white; border-radius:5px;");
ui->pwd_line->setStyleSheet("background-color:white; border-radius:5px;");
//按钮设置
ui->login_btn->setStyleSheet("background-color:white; border-radius:10px;");
ui->cancel_btn->setStyleSheet("background-color:white; border-radius:10px;");
//基于qt4版本的connect
connect(ui->cancel_btn, SIGNAL(clicked()), this, SLOT(cancel_slots()));
//基于qt5版本的connect
connect(ui->login_btn, &QPushButton::clicked, this, &Work2::login_slots);
}
Work2::~Work2()
{
delete ui;
}
//登录的槽
void Work2::login_slots()
{
if(ui->account_line->text() == "admin" && ui->pwd_line->text() == "123456"){
qDebug() << "登录成功";
this->close();
}else{
qDebug() << "登录失败";
ui->pwd_line->clear();
}
}
//取消的槽
void Work2::cancel_slots()
{
this->close();
}