Please nominate your Qt Champions for 2021!

[Solved] Accepted signal from QDialogButtonBox

  • Hi all

    I am making a login screen where the user has to enter his username and password. I use a QDialogButtonBox with ok and cancel buttons. My problem is if the user enters incorrect credentials and clicks on the ok button the button is somehow always connected to the accepted signal and closes the dialog.

    What can I do so the dialog wont quit when the user enters incorrect credentials, but instead just clears out the input from the user and lets him try again.

    In .net I would simply do this: DialogResult = DialogResult.None to cancel out the closing of the dialog.

    How can I do this in Qt ?


  • Moderators

    Reimplement "QDialog::accept()":

  • Thanks mlong

    this is how I ended up doing it:

    @void LoginScreen::accept()

    bool LoginScreen::LoginToDB()
    bool ret = w->LogintoMusicDB(ui->userLineEdit->text(), ui->passwordLineEdit->text());

        ui->labelError->setText("Could not log into database!");
        return false;
    return true;


Log in to reply