QLineEdit::editingFinished() doesn't work if QLineEdit is empty?
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?
Re: QLineEdit::editingFinished() doesn't work if QLineEdit is empty?
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.
Re: QLineEdit::editingFinished() doesn't work if QLineEdit is empty?
ChrisW67,
It was the validator. The last parameter of QRegularExpression had to be changed from {1,4} to {0,4} to allow empty input:
Code:
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!