#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
,loginBtn(new QPushButton("登录",this))
, ui(new Ui::Widget)
{
ui->setupUi(this);
loginBtn->resize(ui->pushButton->width(),ui->pushButton->height());
loginBtn->move(ui->pushButton->x()-ui->pushButton->width()-60,ui->pushButton->y());
connect(loginBtn,SIGNAL(clicked()),this,SLOT(login_slot()));//点击登录按钮触发
ui->userName_lineEdit->setPlaceholderText("账户名/邮箱");//占位文本
ui->passWord_lineEdit->setPlaceholderText("密码只可输入数字,英文和下划线");//占位文本
ui->passWord_lineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression("[0-9a-zA-A_]*")));//限制输入的格式
ui->userName_lineEdit->setClearButtonEnabled(1);//全部删除键选择
ui->passWord_lineEdit->setClearButtonEnabled(1);
ui->passWord_lineEdit->setEchoMode(QLineEdit::Password);//密码显示
}
Widget::~Widget()
{
delete ui;
}
void Widget::login_slot(){
if(ui->userName_lineEdit->text()=="123abc"&&ui->passWord_lineEdit->text()=="luliankai"){//判断账户密码是否符合
qDebug("login success!");//终端输出
QMessageBox::information(NULL, "Title", "login success!", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);//登录成功弹窗
}else{
QMessageBox::information(NULL, "Title", "login failed.\n""Pleasa input username/passward again.", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);//登录失败弹窗
ui->passWord_lineEdit->home(true);
ui->passWord_lineEdit->del();
}
}
void Widget::on_pushButton_clicked()
{
this->close();
}
Qt的验证账户密码实例
最新推荐文章于 2024-09-10 17:20:04 发布