Results 1 to 5 of 5

Thread: How many validators can be applied to a single QLineEdit?

  1. #1
    Join Date
    Jun 2008
    Location
    Glenwood, NJ USA
    Posts
    32
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default How many validators can be applied to a single QLineEdit?

    I have a QLineEdit in a dialog box I am creating that allows entering an IP address. I have used a QRegExp validator to ensure that it takes the form:

    "[0-2][0-9][0-9][.][0-2][0-9][0-9][.][0-2][0-9][0-9][.][0-2][0-9][0-9]"

    (I know I need some improvement with regular expressions...)

    This works ok but I still need to range check so each of the four values are within 0-255.

    Can multiple validators be applied to the same widget?

    Or, am I going about this all wrong?

    I was thinking it might be better to break down the QLineEdit into four separate ones, use the range checking of a QIntValidator and then convert to one single QString after it is valid?
    Last edited by awhite1159; 12th July 2008 at 14:04.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How many validators can be applied to a single QLineEdit?

    Quote Originally Posted by awhite1159 View Post
    This works ok but I still need to range check so each of the four values are within 0-255.
    You can achieve this with a regular expression.

    Quote Originally Posted by awhite1159 View Post
    Can multiple validators be applied to the same widget?
    No, but you can create a CompositeValidator class that will aggregate several validators.

  3. The following user says thank you to jacek for this useful post:

    awhite1159 (12th July 2008)

  4. #3
    Join Date
    Jun 2008
    Location
    Glenwood, NJ USA
    Posts
    32
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: How many validators can be applied to a single QLineEdit?

    Thanks Jacek.

    As I said, I need to improve my regular expressions knowledge. Time to pull out my O'Reilly AWK reference and read up on regular expressions.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How many validators can be applied to a single QLineEdit?

    Quote Originally Posted by awhite1159 View Post
    Time to pull out my O'Reilly AWK reference and read up on regular expressions.
    See this one: http://regex.info/

  6. #5
    Join Date
    Jun 2008
    Location
    Glenwood, NJ USA
    Posts
    32
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: How many validators can be applied to a single QLineEdit?

    Got it:
    QRegExp rx("(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)");

    (All on a single line.)

Similar Threads

  1. Pointer Question related to QLineEdit
    By ChrisReath in forum Qt Programming
    Replies: 1
    Last Post: 23rd May 2008, 15:13
  2. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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
  •  
Qt is a trademark of The Qt Company.