LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   QT: Keep dialog alive after error in onAccepted() (https://www.linuxquestions.org/questions/programming-9/qt-keep-dialog-alive-after-error-in-onaccepted-873539/)

Ramurd 04-07-2011 03:50 AM

QT: Keep dialog alive after error in onAccepted()
 
Well, here I am again and not finding how I can get what I want:

I have (for example) a login dialog; it runs fine and does what it is supposed to do, except:
If a user logs on with wrong credentials, how can I keep this window alive? When the onAccepted() is triggered, the window is closed, no matter what. Would/should I have to execute the window again, as in this->exec()?

It seems a bit recursive to me... So, I was hoping I could find a property that would abort the deletion of the window; so I can clear the LineEdit for password and set focus on it... just what a user would expect to happen.

On success the window should close of course, as well as on the cancel button.

Ramurd 04-07-2011 07:33 AM

hmm... it seems simpler than expected:

PHP Code:

void LoginRemoteDialog::on_buttonBox_accepted()
{
    if(
ui->PasswordInput->text().isEmpty())
    {
        
QMessageBox::critical(this,"Empty password provided""You provided an empty password, that's not nice!");

        
ui->PasswordInput->setFocus();
        
this->show();
    }


Just giving the appropriate input the focus and call show()... can it be this easy?

Ramurd 04-07-2011 03:45 PM

tested it out on both Linux and Windows, and indeed it is as simple as this. However, MainWindow is shown and then this loginwindow is shown again with the focus where stated.
For niceness' sake, you might also want to set the cursor at the start in the PasswordInput. Marking the thread as solved though :-)


All times are GMT -5. The time now is 12:18 AM.