![]() |
Home · Overviews · Examples |
The QValidator class provides validation of input text. More...
Inherits QObject.
Inherited by QDoubleValidator, QIntValidator, and QRegExpValidator.
The QValidator class provides validation of input text.
The class itself is abstract. Two subclasses, QIntValidator and QDoubleValidator, provide basic numeric-range checking, and QRegExpValidator provides general checking using a custom regular expression.
If the built-in validators aren't sufficient, you can subclass QValidator. The class has two virtual functions: validate and fixup.
validate must be implemented by every subclass. It returns Invalid, Intermediate or Acceptable depending on whether its argument is valid (for the subclass's definition of valid).
These three states require some explanation. An Invalid string is clearly invalid. Intermediate is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). QValidator defines Intermediate as the property of a string that is neither clearly invalid nor acceptable as a final result. 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 Intermediate.
Here are some examples:
fixup is provided for validators that can repair some user errors. The default implementation does nothing. QLineEdit, for example, will call fixup if the user presses Enter (or Return) and the content is not currently valid. This allows the fixup function the opportunity of performing some magic to make an Invalid string Acceptable.
A validator has a locale, set with setLocale. It is typically used to parse localized data. For example, QIntValidator and QDoubleValidator use it to parse localized representations of integers and doubles.
QValidator is typically used with QLineEdit, QSpinBox and QComboBox.
See also QIntValidator, QDoubleValidator, QRegExpValidator, and Line Edits Example.
Copyright © 2007 Trolltech | Trademarks | Qt Jambi 4.3.2_01 |