使用手动连接,将登录框中的取消按钮使用第二中连接方式,右击转到槽,在该槽函数中,调用关闭函数
将登录按钮使用qt4版本的连接到自定义的槽函数中,在槽函数中判断ui界面上输入的账号是否为"admin",密码是否为"123456",如果账号密码匹配成功,则输出“登录成功”,并关闭该界面,如果匹配失败,则输出登录失败,并将密码框中的内容清空
#include "myday2_04_.h"
#include "ui_myday2_04_.h"Myday2_04_::Myday2_04_(QWidget *parent): QWidget(parent), ui(new Ui::Myday2_04_){ui->setupUi(this);this->setStyleSheet("background-color:rgb(255,255,255)");ui->label->setPixmap(QPixmap(":/QTTTTTTTTTTTTTT/z.jpg"));ui->label->setScaledContents(true);ui->label_2->setPixmap(QPixmap(":/QTTTTTTTTTTTTTT/a.jpg"));ui->label_2->setScaledContents(true);ui->label_3->setPixmap(QPixmap(":/QTTTTTTTTTTTTTT/c.png"));ui->label_3->setScaledContents(true);//设置占位ui->user->setPlaceholderText("账号");ui->line->setPlaceholderText("密码");//设置显示模式(···)ui->line->setEchoMode(QLineEdit::Password);
}Myday2_04_::~Myday2_04_()
{delete ui;
}void Myday2_04_::on_pushButton_clicked()
{//获取输入的文本QString user1 = ui->user->text();QString line1 = ui->line->text();if(user1.isEmpty() || line1.isEmpty()){QMessageBox::warning(this, "Warning", "请输入账号或密码");}else{//判断账号和密码正确性if(user1 == "admin" && line1 == "123456"){QMessageBox::information(this, "Access Granted", "登陆成功");}else{QMessageBox::warning(this, "Access Denied", "登录失败:密码错误");ui->user->clear();ui->line->clear();}}
}void Myday2_04_::on_qux_clicked()
{this->close();
}