Frage

I'm in trouble. I have a QDialog as a login form. When I log in, the form closes and my mainwindow will appear. My login is fine but when it closes it returns QDialog::Rejected.

What can I do to prevent the return of QDialog::Rejected? And when will it even return QDialog::Rejected?

Code when I log in :

void Login::on_cmdLogin_clicked()
{

    if( ui->txtUsernameLogin->text().isEmpty()  || ui->txtPassLogin->text().isEmpty() )
    {
            QMessageBox::critical(this, "Vocabulary Trainer", "Please fill in both textboxes.", QMessageBox::Ok);
            return;
    }
    User user(filepath + "/users.txt");
    if ( user.checkPassword( ui->txtUsernameLogin->text(), ui->txtPassLogin->text() ))
    {
        username = ui->txtUsernameLogin->text();
        close();
    }
    else
        QMessageBox::warning(this, "Vocabulary Trainer", "Sorry, your password is incorrect.\nPlease type in the correct password.", QMessageBox::Ok);
}

main() :

MainWindow w;   //Real Window
Login lg(0);    //Login Window

lg.set_path(workspace_path);
lg.setModal(true);
if(lg.exec() == QDialog::Rejected)
    QMessageBox::critical(0, "rr", "", QMessageBox::Ok);
else
    w.show();   //Shows the real window

It'll always rejected.

War es hilfreich?

Lösung

Try to call done(QDialog::Accepted); instead close(); in Login::on_cmdLogin_clicked()

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top