qt에서 로그인 페이지를 구현하려고하는데 이상한 문제가 발생했습니다. 두 가지 유형의 비밀번호를 확인하고 싶습니다. 하나는 일반 암호이고 두 번째는 마스터 암호입니다. 사용자가 비밀번호를 5 회 잘못 입력하면 마스터 비밀번호를 입력해야하며, 비밀번호 3 개도 잘못 입력하면 디스플레이에 오류가 발생합니다.
코드를 작성했지만 수정할 수없는 문제가 있습니다. 내 로그인 코드는 다음과 같습니다.
void FormLogin::OnLogin()
{
QString password = passLineEdit->text();
// Checking if username or password is empty
if (password.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "Password field is empty!");
} else if (password == "pass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong password!!! Only %1 attempt(s) left!").arg(4-attempt));
attempt++;
if (attempt == 5){
QMessageBox::information(this, tr("Warning!"), QString("The device is locked due to too many failed attempts. Please enter the master password to unlock the device now."));
connect(loginButton, SIGNAL(clicked()), this, SLOT(OnMasterLogin()));
return;}
}
}
void FormLogin::OnMasterLogin()
{
QString mpassword = passLineEdit->text();
// Checking if username or password is empty
if (mpassword.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "MPassword field is empty!");
} else if (mpassword == "masterpass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong mpassword!!! Only %1 attempt(s) left!").arg(2-master_attempt));
master_attempt++;
if (master_attempt == 3){
QMessageBox::information(this, tr("Warning!"), QString("The device is permanently locked due to too many failed attempts. Please contact the device manufacturer."));}}
}
첫 번째 함수의 시도가 5 일 때만 두 번째 함수를 호출하고 싶습니다.하지만 5 회 루프 후에 제 코드는 두 번째 함수를 호출하지만 첫 번째 함수와 두 번째 함수를 동시에 실행합니다. 아무도 내가 어디에서 잘못하고 있는지 말해 줄 수 있습니까? 함수를 함께 결합하고 두 번째 함수를 첫 번째 루프 내부에 중첩 된 루프로 사용하려고 시도했지만 "if 루프"조건 내에 설정하더라도 전체 함수를 호출합니다.
void FormLogin::OnLogin()
{
QString password = passLineEdit->text();
// Checking if username or password is empty
if (password.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "Password field is empty!");
} else if (password == "pass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong password!!! Only %1 attempt(s) left!").arg(4-attempt));
attempt++;
if (attempt == 5){
QMessageBox::information(this, tr("Warning!"), QString("The device is locked due to too many failed attempts. Please enter the master password to unlock the device now."));
QString mpassword = passLineEdit->text();
// Checking if username or password is empty
if (mpassword.isEmpty())
{QMessageBox::information(this, tr("Warning!"), "MPassword field is empty!");
} else if (mpassword == "masterpass")
{this->destroy();
} else {
QMessageBox::information(this, tr("Warning!"), QString("Wrong mpassword!!! Only %1 attempt(s) left!").arg(2-master_attempt));
master_attempt++;
if (master_attempt == 3){
QMessageBox::information(this, tr("Warning!"), QString("The device is permanently locked due to too many failed attempts. Please contact the device manufacturer."));}}}
}
}
첫 번째 함수는 다음 코드를 사용하여 호출됩니다.
connect(loginButton, SIGNAL(clicked()), this, SLOT(OnLogin()));
어떤 제안이라도 대단히 감사합니다.
loginButton :: clicked ()를 FormLogin :: OnLogin ()에 이미 연결했다고 가정합니다. 이 방법에서는 5 번 시도 할 때 FormLogin :: OnMasterLogin () 에 다른 연결 을 추가 하지만 원래 연결은 그대로 둡니다. disconnect ()를 사용하거나 FormLogin :: OnLogin ()에 논리를 추가하여 현재 "마스터 로그인"모드 인 경우 구제 조치를 취하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다