我遇到了麻烦。我有一个QDialog作为登录表单。当我登录时,表单关闭,我的主窗口将出现。我的登录很好但是当它关闭时它会返回QDialog :: Rejected。
我该怎么做才能阻止QDialog :: Rejected的返回?什么时候它甚至会返回QDialog ::拒绝?
登录时的代码:
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
它总是会被拒绝。
答案 0 :(得分:2)
尝试在done(QDialog::Accepted);
close();
而不是Login::on_cmdLogin_clicked()