槽函数声明
private slots:
void on_ed_textChanged();
void on_pushButton_clicked();
};
槽函数定义
void Widget::on_ed_textChanged()//文本框
{
if(ui->ed1->text().length()>=5
&&ui->ed2->text().length()>=5)
{
ui->pushButton->setStyleSheet("background-color:green");
}
else
ui->pushButton->setStyleSheet("background-color:red");
}
void Widget::on_pushButton_clicked()//按钮
{
if(ui->ed1->text()=="Admin"
&&ui->ed2->text()=="12345")
qDebug("登录成功");
else
{
qDebug("账号或密码错误,请重新输入");
ui->ed1->clear();
ui->ed2->clear();
}
}
信号与槽连接
QObject::connect(ui->ed1,&QLineEdit::textChanged,
this,&Widget::on_ed_textChanged);
QObject::connect(ui->ed2,&QLineEdit::textChanged,
this,&Widget::on_ed_textChanged);
QObject::connect(ui->pushButton,&QPushButton::clicked,
this,&Widget::on_pushButton_clicked);