PDA

View Full Version : QLineEdit::editingFinished() doesn't work if QLineEdit is empty?



mireiner
8th July 2016, 23:33
Hi there!

QDialog with multiple QLineEdit fields (Qt 5.7.0 desktop application on Windows 10):

If a QLineEdit is losing focus and it isn't empty then the signal editingFinished() is emitted.
But if QLineEdit is empty the signal editingFinished() is not emitted. No matter if it lost focus because of tab key action or left mouse click on next or another QLineEdit field.

Why is edingFinished() isn't emitted if the QLineEdit is empty? Whats wrong?

ChrisW67
9th July 2016, 03:34
One reason: if the line edit has a validator and it does not return QValidator::Acceptable, or an input mask that is not matched/complete, then editingFinished() is not emitted.

mireiner
9th July 2016, 10:59
ChrisW67,

It was the validator. The last parameter of QRegularExpression had to be changed from {1,4} to {0,4} to allow empty input:


QValidator *validator;
validator = new QRegularExpressionValidator(QRegularExpression("[A-Z 1-5]{1,4}"), this);
validator = new QRegularExpressionValidator(QRegularExpression("[A-Z 1-5]{0,4}"), this); // works
Thank you very much for your help!