Results 1 to 3 of 3

Thread: What to Expect from a QLineEdit Validator.

  1. #1
    Join Date
    Jun 2012
    Posts
    193
    Thanks
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default What to Expect from a QLineEdit Validator.

    I want to have a QLineEntry that will acccept 8-63, printable, hex characters (wpa password).

    A QRegExpValidator for this could look like this:

    Qt Code:
    1. QRegExp rx("[ -~]{8,63}");
    2. ui->hotSpot_PSK->setValidator(new QRegExpValidator(rx,this));
    To copy to clipboard, switch view to plain text mode 

    I can verify that

    Qt Code:
    1. ui->hotSpot_PSK->hasAcceptableInput())
    To copy to clipboard, switch view to plain text mode 

    is true and false when expected. But, this doesn't seem to have any affect on the user can be entered. For example, the LineEntry "closes" when enter is pressed, even if less than 8 characters are entered.

    Do I need to have code that tests for hasAcceptableInpu() in all the slots that would allow invalid text to be entered, including the buttons that do accept(), like OK and Apply in the typical button box?

    If so, what does the validator really do for me (versus just a QRegExp test on the text()?

    Thanks!

  2. #2
    Join Date
    Jun 2012
    Posts
    193
    Thanks
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What to Expect from a QLineEdit Validator.

    When I subclass QRegExpValidator and provide an inplementation of validate, things work like I expected. For example, it's not possible to delete characters to make the text less than 8 characters long.

    I figured this is how it would work without needing to implement validate. If the RegExp didn't match, it would return Invalid, if it matched, Acceptable.

    Am I missing something? Is it really necessary to subclass and inplement the validate method versus just defining the RegExp?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,796
    Thanks
    263
    Thanked 777 Times in 767 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: What to Expect from a QLineEdit Validator.

    I don't see anything wrong with what you've done, except that QLineEdit does not take ownership of the validator, so setting it the way you do causes a (small) memory leak. You should not have to subclass QRegExpValidator.

    You should not be getting the editingFinished() signal from the line edit if the widget loses focus (e.g. Enter is pressed) while the input is invalid. Is that what you observe?

    Does the same thing happen if you use QRegularExpressionValidator instead?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QLineEdit inputMask and validator
    By vhptt in forum Newbie
    Replies: 3
    Last Post: 1st September 2012, 03:36
  2. QLineEdit validator() problem
    By ayanda83 in forum Newbie
    Replies: 2
    Last Post: 31st August 2012, 00:40
  3. QLineEdit validator
    By pobere in forum Newbie
    Replies: 2
    Last Post: 5th November 2011, 11:16
  4. Use QLineEdit with mask AND validator for money OUTPUT
    By luboni in forum Qt Programming
    Replies: 4
    Last Post: 16th August 2011, 18:29
  5. Replies: 1
    Last Post: 26th December 2008, 13:59

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.