[SOLVED] QLineEdit and QValidator issue
If I use QLineEdit::setValidator() once, everything works fine. But strange things happens when I call QLineEdit::setValidator() many times (with different validators).
Here is my test case: https://github.com/emanuel-koczwara/qt-validator-test
For example, if you enter an ip address (ipValidator works at that time) and you click pushButton, then ipValidator is replaced by intValidator (and ip address is replaced by an int value). New validator doesn't work at first, you can enter any character, but if you use backspace, then the validator starts working. Any ideas?
Couldn't think of a solution so fast, but as a work around, after setting the new validator you might want to clear the QLineEdit text? That might do the trick?
Hmm, you do set a new value in the lineEdit. Would you be so kind to post that piece of code? Then we are able to regenerate the problem our self.
Maybe this will help:
setValidator(0); // remove old seperator
ui->lineEdit->setText(""); // clear the old text
setValidator(<new one>); // Set new validator
ui->lineEdit->setText(QString::number(5)); // set new value in lineedit
There might be some issue when setting a new validator on a LineEdit when the text in the lineEdit does not match the given validator. So to be sure, first clear the text, then set the new validator, then set a new 'valid' text.
Ok, solved. I need to: 1) reset old validator 2) set new text 3) set new validator.