Results 1 to 3 of 3

Thread: How to call QValidator derived object

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Wink How to call QValidator derived object

    I have a QLineEdit field which I need to have the user either enter 0 characters or 10 characters and nothing in between. I have written a QValidator class that returns invalid if anything other than 0 or 10 characters are entered. It also returns intermediate other times.

    How do I prevent the user from moving out of the QLineEdit field until the field is correct?

    Here's my code snippets:
    (validate routine from QValidator derived class)
    Qt Code:
    1. QValidator::State ValidatorWepKey::validate(QString &input, int &pos) const
    2. {
    3. if (input.length() == 0)
    4. {
    5. return Acceptable;
    6. }
    7. else if (input.length() < m_minLength)
    8. {
    9. return Intermediate;
    10. }
    11. else if (input.length() == m_minLength)
    12. {
    13. return Acceptable;
    14. }
    15. else
    16. {
    17. return Invalid;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    Main code:
    Qt Code:
    1. QLineEdit m_pKey1 = new QLineEdit();
    2. m_pKey1->setValidator(new ValidatorWepKey(10, this)); // should prevent
    To copy to clipboard, switch view to plain text mode 

    When do I call the ValidatorWepKey.validate()? Is that when I get the signal that the user is attempting to exit the field? How do I keep them in the field until it is correct?

    - BRC
    Last edited by wysota; 23rd March 2007 at 23:50. Reason: missing [code] tags

Similar Threads

  1. call bash/terminal command with QT
    By myta212 in forum Newbie
    Replies: 1
    Last Post: 13th November 2006, 15:38
  2. Call on Parent Object
    By hufgardm in forum Newbie
    Replies: 1
    Last Post: 7th September 2006, 15:11
  3. why cant i call setGeometry
    By freegnu in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2006, 04:59
  4. Passing Object to dll
    By ankurjain in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 09:50
  5. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 00:32

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.