PDA

View Full Version : setValidator and setEchoMode on LineEdit erases the info bad behaviour



roseicollis
15th May 2015, 09:57
Hi,

I have a LineEdit for a password which has to be numeric and max. lenght is 8. Also it has to display asterisks or dots as I see it does with my code. My problem is that if I put the next code when I write the 9th digit which should not let you to, it ERASES all the lineedit and writtes it as the first one. O.o Why do I have this behaviour?


QRegExp rx212("[0-9]{0,8}");
QValidator *validator212 = new QRegExpValidator(rx212, this);

// this both lines make it goes wrong
le_Pwd->setValidator(validator212); // this line alone allows me to put 0-8 numbers, no more. This is what I want but mask with ******
le_Pwd->setEchoMode(QLineEdit::Password); // this line alone allows me to show dots instead of numbers to mask the pwd. with no limit

Thank you!

west
15th May 2015, 11:01
lol, it works fine with Qt 4.8 but erases with 5.4...

Use: http://doc.qt.io/qt-4.8/qlineedit.html#maxLength-prop

roseicollis
15th May 2015, 11:22
I use Qt 4.8.5 and it erases... XD

I used too the setmaxlength but then if I write p.e. 12345 and then a letter, the lineedit is erased again TT____TT

Edit:

Qt Creator 2.8.0
Based on Qt 4.8.5 (GCC 4.7.2 20121109 (Red Hat 4.7.2-8), 32 bit)

roseicollis
18th May 2015, 08:03
May this be a bug or something like this?

I tried also catching the input this way:

in .h:


class MyValidator2: public QValidator {
public:
MyValidator2(QObject* parent=nullptr): QValidator(parent) {}
State validate(QString& input, int&) const override {
if (input=="0" or input=="1" or input=="2" or input=="3"
or input=="4" or input=="5" or input=="6" or input=="7" or
input=="8" or input=="9")
return QValidator::Acceptable;
}
};

in constructor .cpp:


auto validator12 = new MyValidator2(parent);
le_Pwd->setValidator(validator12);
le_Pwd->setMaxLength(8);
le_Pwd->setEchoMode(QLineEdit::Password);


But if i write 1 and then 2, the first one is erased and it only allows me to write one number.... and I don't know if its the bug or if I did wrong the validator ...