Hmm, if I make a suggestion is to not have the D1 (I presume a dialog) start a new dialog (D2.exec), but rather have the D1 be started by the parent, wait for it to be closed or accepted, check the codes entered or maybe use the default return codes if the entry was valid and go and execute the D2 dialog, or go straight past it.
@void D1::D1()
{
iTries = 1;
ui->lineEdit->clear();
ui->lineEdit_2->clear();
ui->label_3->setText(QString("Attempt %1 of 3").arg(QString::number(iTries)));
}
void D1::on_pushButton_clicked()
{
// Check if log in was correct this time
if ( (!ui->lineEdit->text().isEmpty()) &&
(!ui->lineEdit_2->text().isEmpty()))
{
if((ui->lineEdit->text()=="admin") && (ui->lineEdit_2->text()=="admin"))
{
accept(); // this will close the dialog with an accept return code!
}
}
// Check if the user did it too many times
iTries++;
if (iTries > 3)
{
QMessageBox::information(this, "Log in Failed!", "Number of attempts reached");
reject(); // This will close the dialog and give a reject return code!
}
// setup the Gui for next login text
ui->lineEdit->clear();
ui->lineEdit_2->clear();
ui->label_3->setText(QString("Attempt %1 of 3").arg(QString::number(iTries)));
}
// parent code:
D1 * D1Dialog = new D1;
if (D1Dialog->exec() == QDialog::Accepted)
{
D2 * D2Dialog = new D2;
D2->exec();
}
@
It is also better practice to use the class pointer <name> = new class; for dialogs etc. This has to do with stack and heap stuff in the background. Don't be afraid to use the pointers. Qt is very great in code editor to replace a used . into a -> for members and to destroy the allocated data when the dialog of his parent is destroyed.
Good luck with it.
(btw, I didn't test the code, so no idea if it is perfect already)