【问题标题】:Qt When will the dialog return QDialog::RejectedQt 对话框何时返回 QDialog::Rejected
【发布时间】:2013-05-02 15:06:57
【问题描述】:

我有麻烦了。我有一个 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

它总是会被拒绝。

【问题讨论】:

    标签: c++ qt qdialog


    【解决方案1】:

    尝试在Login::on_cmdLogin_clicked() 中调用done(QDialog::Accepted); 而不是close();

    【讨论】:

    • 工作。但是为什么我必须使用这个而不是关闭?
    • Close set return value of exec to 0. 但是QDialog::Accepted ==1, QDialog::Rejected == 0. 你需要设置return value为1
    猜你喜欢
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多