Answer the question
In order to leave comments, you need to log in
How to fix a bug with authorization?
In QT, authorization is done by entering a login and password. But if you close the input window, it takes it as the correct password entry and puts the window on the trail.
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QDialog(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
ui->label->hide();
}
Login::~Login()
{
delete ui;
}
void Login::on_OkayButton_clicked()
{
QVector<QString> Logins[2];
Logins[0].push_back("log");
Logins[1].push_back("123");
Logins[0].push_back("login");
Logins[1].push_back("12345");
Logins[0].push_back("gol");
Logins[1].push_back("12345");
int index=0;
for(int i=0; i<Logins[0].size();i++)
{
if (ui->LoginEdit->text()==Logins[0][i])
{
index=i;
}
}
if(ui->PaswordEdit->text()==Logins[1][index])
{
rightPass=true;
close();
}
else
{
rightPass=false;
ui->label->show();
}
}
void Login::on_label_destroyed()
{
rightPass=false;
ui->label->show();
}
Answer the question
In order to leave comments, you need to log in
override closeEvent:
void closeEvent(QCloseEvent * event){
if (!rightPass){
qApp->closeAllWindows();
}
}
on_label_destroyed - it will not be needed
to store login-password pairs, I would use QMap
so, in my opinion, it's easier to check the correctness of the input
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question