Results 1 to 4 of 4

Thread: setValidator and setEchoMode on LineEdit erases the info bad behaviour

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default setValidator and setEchoMode on LineEdit erases the info bad behaviour

    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?

    Qt Code:
    1. QRegExp rx212("[0-9]{0,8}");
    2. QValidator *validator212 = new QRegExpValidator(rx212, this);
    3.  
    4. // this both lines make it goes wrong
    5. le_Pwd->setValidator(validator212); // this line alone allows me to put 0-8 numbers, no more. This is what I want but mask with ******
    6. le_Pwd->setEchoMode(QLineEdit::Password); // this line alone allows me to show dots instead of numbers to mask the pwd. with no limit
    To copy to clipboard, switch view to plain text mode 
    Thank you!

  2. #2
    Join Date
    Feb 2012
    Location
    Warsaw, Poland
    Posts
    37
    Thanks
    3
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: setValidator and setEchoMode on LineEdit erases the info bad behaviour

    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
    Last edited by west; 15th May 2015 at 11:08.

  3. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setValidator and setEchoMode on LineEdit erases the info bad behaviour

    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)
    Last edited by roseicollis; 15th May 2015 at 11:35.

  4. #4
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setValidator and setEchoMode on LineEdit erases the info bad behaviour

    May this be a bug or something like this?

    I tried also catching the input this way:

    in .h:

    Qt Code:
    1. class MyValidator2: public QValidator {
    2. public:
    3. MyValidator2(QObject* parent=nullptr): QValidator(parent) {}
    4. State validate(QString& input, int&) const override {
    5. if (input=="0" or input=="1" or input=="2" or input=="3"
    6. or input=="4" or input=="5" or input=="6" or input=="7" or
    7. input=="8" or input=="9")
    8. return QValidator::Acceptable;
    9. }
    10. };
    To copy to clipboard, switch view to plain text mode 

    in constructor .cpp:

    Qt Code:
    1. auto validator12 = new MyValidator2(parent);
    2. le_Pwd->setValidator(validator12);
    3. le_Pwd->setMaxLength(8);
    4. le_Pwd->setEchoMode(QLineEdit::Password);
    To copy to clipboard, switch view to plain text mode 


    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 ...

Similar Threads

  1. Replies: 1
    Last Post: 19th January 2014, 23:29
  2. QLineEdit problem with setValidator
    By dominate in forum Qt Programming
    Replies: 4
    Last Post: 20th January 2011, 14:34
  3. setValidator on QLineEdit
    By osiris81 in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2009, 14:21
  4. lineEdit + comboBox behaviour widget
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 22nd April 2009, 11:34
  5. setValidator
    By :db:sStrong in forum Qt Programming
    Replies: 11
    Last Post: 16th May 2006, 09:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.