C++&QT实现用户输入三次错误密码退出的代码
界面是用QT编的 功能实现用了C++和数据库
登陆界面
代码块
void login::on_login_2_clicked()
{
QSqlQuery query;
QString acc = ui->acc->text();
int pwd = ui->pwd->text().toInt();
QString str = QString("SELECT `name`,student_id from stu where name = '%1' and student_id = %2")
.arg(acc).arg(pwd);
QApplication::exit();
if(!query.exec(str)){
qDebug() << str;
return;
}
if(query.next()){
QMessageBox::information(this, "错误", "登陆成功");
login::reject();
guanli.show();
}else{
// QApplication::exit();
QMessageBox::warning(this, "错误", "登陆失败");
}