0
我有麻煩了。我有一個QDialog作爲登錄表單。當我登錄時,窗體關閉,我的主窗口將出現。我的登錄很好,但是當它關閉時,它返回QDialog :: Rejected。Qt什麼時候對話框會返回QDialog :: Rejected
我該怎麼做才能防止QDialog返回::拒絕?什麼時候它甚至會返回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);
}
的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
它會永遠拒絕。
合作。但爲什麼我必須用這個而不是close? – 2013-05-02 15:21:12
關閉設置exec的返回值爲0.但QDialog :: Accepted == 1,QDialog :: Rejected == 0.你需要設置返回值爲1 – 2013-05-02 15:32:37
哦,謝謝。不知道close會將返回值設置爲0。 – 2013-05-02 15:39:48