1
votes

I have a dialog with LineEdit elements. I want the dialog to close if ENTER is pressed so I added a slot for the returnPressed() signal:

ChPasswd::ChPasswd(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ChPasswd)
{
    ui->setupUi(this);
    connect(ui->NewPasswordInput, SIGNAL(returnPressed()), SLOT(checkPasswords()));
}

At some point I open a message box:

QMessageBox mb(...);
mb.exec();

The box opens and gets the focus. The problem is that when I press ENTER now, the returnPressed signal in ChPasswd fires and checkPasswords() is called. Why is this keyboard event handled?

1
What is the message box' parent? - Marc Mutz - mmutz
I did. Nothing changed. I also tried to set mb.setWindowModality(Qt::ApplicationModal) without success - slosd
Alright, I just figured it out. Since this is a dialog pressing ENTER automatically calls another slot. This slot also calls checkPasswords() and therefor created a second message box which appears as soon as the first one was closed. - slosd
@slosd: If you've solved your problem, you should submit it as a self-answer, so that the question doesn't appear to be unanswered :) - sam-w

1 Answers

0
votes

Alright, I just figured it out. Since this is a dialog pressing ENTER automatically calls another slot. This slot also calls checkPasswords() and therefor created a second message box which appears as soon as the first one was closed.