The QValidator class provides validation of input text. More...
#include <qvalidator.h>
Inherits QObject.
Inherited by QDoubleValidator and QIntValidator.
The class itself is abstract; two subclasses provide rudimentary numeric range checking.
The class includes two virtual functions, validate() and fixup().
validate() is pure virtual, so it must be implemented by every subclass. It returns Invalid, Valid or Acceptable depending on whether its argument is valid (for the class' definition of valid).
The three states require some explanation. An Invalid
string is
clearly invalid. Valid
is less obvious - the concept of
validity is slippery when the string is incomplete (still being
edited). QValidator defines Valid
as the property of a string
that it is not clearly invalid. Acceptable
means that the string
is acceptable as a final result. One might say that any string that
is a plausible intermediate state during entry of an Acceptable
string is Valid.
Here are some examples:
Acceptable,
the empty string and 1114 are Valid
and asdf is Invalid.
Acceptable,
"http://www.troll.no/," is Valid
(it can be a
cut-and-paste job that accidentally took in a comma at the end), the
empty string is valid (the user might select and delete all of the
text in preparation to entering a new URL), and "http:///./moron"
is Invalid.
Acceptable,
"11" and the empty string are Valid,
and
"http://www.troll.no" and "hour" are Invalid.
fixup() is provided for validators that can repair some or all user
errors. The default does nothing. QLineEdit, for example, will
call fixup() if the user presses Return and the content is not
currently valid, in case fixup() can do magic. This allows some Invalid
strings to be made Acceptable,
too, spoiling the muddy
definition above even more.
QValidator is generally used with QLineEdit, QSpinBox and QComboBox.
Sets up the internal data structures used by the validator. At the moment there aren't any.
Deletes the validator and frees any storage and other resources used.
[virtual]
Attempts to change to be valid according to this validator's rules. Need not result in a valid string - callers of this function must re-test afterwards. The default does nothing.
Reimplementation notes:
Note that input may not be the only QString object referencing this string, so it's almost always necessary to detach() the string at the start of the code:
input.detach();
You can change input even if you aren't able to produce a valid string. For example an ISBN validator might want to delete every character except digits and "-", even if the result is not a valid ISBN, and a last-name validator might want to remove white space from the start and end of the string, even if the resulting string is not in the list of known last names.
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.
Copyright © 1999 Troll Tech | Trademarks | Qt version 2.0.2
|