QLineEdit::editingFinished() [signal] is emitted twice
-
Hi all,
I have a problem with QLineEdit. The signal "editingFinished()" is emitted twice when "Enter key" is pressed.
My Slot:
void Dialog::on_LineEdit_editingFinished()
{
if(ui->LineEdit->text().toDouble()<1000)
QMessageBox::information(this,"Information","Incorrect value ");
}QMessageBox is called twice when Enter key is pressed ( but it is called one when the line edit loses focus).
How to fix this problem?
Please advise. -
Looks like you hit a Qt bug.
See here:
https://bugreports.qt-project.org/browse/QTBUG-40This has been around for a long time and I'm not sure what's the policy on reopening old bugs, maybe some "inside" folks can advise on that.
In my code to work around the issue I added a check to see if the text has changed since the last triggering.
-
Hi and welcome to devnet,
As a quick workaround you can use:
@
if(lineEdit->text().toDouble()<1000) {
lineEdit->blockSignals(true);
QMessageBox::information(this, "Information", "Incorrect value");
lineEdit->blockSignals(false);
}
@ -
Thank you, frankiefrank.
Thank you, SGaist. It works great!@
void Dialog::on_LineEdit_editingFinished()
{
if(ui->LineEdit->text().toDouble()<1000)
{
ui->LineEdit->blockSignals(true);
QMessageBox::information(this,“Information”,“Incorrect value “);
ui->LineEdit->blockSignals(false);
}
}
@ -
Please edit your post to include [SOLVED] :)