Results 1 to 6 of 6

Thread: Use of QValidator in QLineEdit

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Use of QValidator in QLineEdit

    Hello everyone, I have a question about the use of QValidator in QLineEdit:
    Qt Code:
    1. QRegExp rx("^[1-9]{1, 3}$");
    2. QLineEdit *lineedit = new QLineEdit(this);
    3. lineedit->setValidator(new QRegExpValidator(rx, lineedit));
    To copy to clipboard, switch view to plain text mode 
    The widget will not let me enter any numbers, why?
    I expected at least to enter a number between 1 and 999, but nothing.
    What's missing?

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Use of QValidator in QLineEdit

    use QIntValidator

  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Use of QValidator in QLineEdit

    Yes mentalmushroom, works with QIntValidator but I wanted to use QRegExpValidator...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Use of QValidator in QLineEdit

    What if you use {0,3} and not {1,3}? Also skip "^" and "$", they are not required here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Use of QValidator in QLineEdit

    I then found out where wrong:
    Qt Code:
    1. {1, 3}
    To copy to clipboard, switch view to plain text mode 
    I put a space after the character ','. the correct form is
    Qt Code:
    1. {1,3}
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Use of QValidator in QLineEdit

    keep in mind this won't let you enter numbers that contain zeros, e.g. 109.

Similar Threads

  1. QValidator problem
    By zgulser in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2011, 04:24
  2. QValidator and ListWidget
    By csvivek in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2008, 19:19
  3. QValidator for QGraphicsTextItem
    By arjunasd in forum Qt Programming
    Replies: 4
    Last Post: 8th August 2007, 15:34
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  5. QLineEdit & QValidator - umm...
    By matheww in forum Qt Programming
    Replies: 3
    Last Post: 20th June 2007, 21:40

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.