0

我有麻烦了。我有一个 QDialog 作为登录表单。当我登录时,表单关闭,我的主窗口将出现。我的登录很好,但是当它关​​闭时它返回 QDialog::Rejected。

我能做些什么来防止 QDialog::Rejected 的返回?它什么时候会返回 QDialog::Rejected?

我登录时的代码:

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);
}

主要的() :

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

它总是会被拒绝。

4

1 回答 1

2

尝试done(QDialog::Accepted);调用close();_Login::on_cmdLogin_clicked()

于 2013-05-02T15:18:50.897 回答