1QValidator(3qt) QValidator(3qt)
2
3
4
6 QValidator - Validation of input text
7
9 #include <qvalidator.h>
10
11 Inherits QObject.
12
13 Inherited by QIntValidator, QDoubleValidator, and QRegExpValidator.
14
15 Public Members
16 QValidator ( QObject * parent, const char * name = 0 )
17 ~QValidator ()
18 enum State { Invalid, Intermediate, Valid = Intermediate, Acceptable }
19 virtual State validate ( QString & input, int & pos ) const = 0
20 virtual void fixup ( QString & input ) const
21
23 The QValidator class provides validation of input text.
24
25 The class itself is abstract. Two subclasses, QIntValidator and
26 QDoubleValidator, provide basic numeric-range checking, and
27 QRegExpValidator provides general checking using a custom regular
28 expression.
29
30 If the built-in validators aren't sufficient, you can subclass
31 QValidator. The class has two virtual functions: validate() and
32 fixup().
33
34 validate() must be implemented by every subclass. It returns Invalid,
35 Intermediate or Acceptable depending on whether its argument is valid
36 (for the subclass's definition of valid).
37
38 These three states require some explanation. An Invalid string is
39 clearly invalid. Intermediate is less obvious: the concept of validity
40 is slippery when the string is incomplete (still being edited).
41 QValidator defines Intermediate as the property of a string that is
42 neither clearly invalid nor acceptable as a final result. Acceptable
43 means that the string is acceptable as a final result. One might say
44 that any string that is a plausible intermediate state during entry of
45 an Acceptable string is Intermediate.
46
47 Here are some examples:
48
49 For a line edit that accepts integers from 0 to 999 inclusive, 42 and
50 123 are Acceptable, the empty string and 1114 are Intermediate and asdf
51 is Invalid.
52
53 For an editable combobox that accepts URLs, any well-formed URL is
54 Acceptable, "http://www.trolltech.com/," is Intermediate (it might be a
55 cut and paste operation that accidentally took in a comma at the end),
56 the empty string is Intermediate (the user might select and delete all
57 of the text in preparation for entering a new URL), and "http:///./" is
58 Invalid.
59
60 For a spin box that accepts lengths, "11cm" and "1in" are Acceptable,
61 "11" and the empty string are Intermediate and"
62 http://www.trolltech.com" and "hour" are Invalid.
63
64 fixup() is provided for validators that can repair some user errors.
65 The default implementation does nothing. QLineEdit, for example, will
66 call fixup() if the user presses Enter (or Return) and the content is
67 not currently valid. This allows the fixup() function the opportunity
68 of performing some magic to make an Invalid string Acceptable.
69
70 QValidator is typically used with QLineEdit, QSpinBox and QComboBox.
71
72 See also Miscellaneous Classes.
73
74 Member Type Documentation
76 This enum type defines the states in which a validated string can
77 exist.
78
79 QValidator::Invalid - the string is clearly invalid.
80
81 QValidator::Intermediate - the string is a plausible intermediate value
82 during editing.
83
84 QValidator::Acceptable - the string is acceptable as a final result,
85 i.e. it is valid.
86
89 Sets up the validator. The parent and name parameters are passed on to
90 the QObject constructor.
91
93 Destroys the validator, freeing any storage and other resources used.
94
96 This function attempts to change input to be valid according to this
97 validator's rules. It need not result in a valid string: callers of
98 this function must re-test afterwards; the default does nothing.
99
100 Reimplementations of this function can change input even if they do not
101 produce a valid string. For example, an ISBN validator might want to
102 delete every character except digits and "-", even if the result is
103 still not a valid ISBN; a surname validator might want to remove
104 whitespace from the start and end of the string, even if the resulting
105 string is not in the list of accepted surnames.
106
108
109 This pure virtual function returns Invalid if input is invalid
110 according to this validator's rules, Intermediate if it is likely that
111 a little more editing will make the input acceptable (e.g. the user
112 types '4' into a widget which accepts integers between 10 and 99) and
113 Acceptable if the input is valid.
114
115 The function can change input and pos (the cursor position) if it wants
116 to.
117
118 Reimplemented in QIntValidator, QDoubleValidator, and QRegExpValidator.
119
120
122 http://doc.trolltech.com/qvalidator.html
123 http://www.trolltech.com/faq/tech.html
124
126 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
127 license file included in the distribution for a complete license
128 statement.
129
131 Generated automatically from the source code.
132
134 If you find a bug in Qt, please report it as described in
135 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
136 help you. Thank you.
137
138 The definitive Qt documentation is provided in HTML format; it is
139 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
140 web browser. This man page is provided as a convenience for those users
141 who prefer man pages, although this format is not officially supported
142 by Trolltech.
143
144 If you find errors in this manual page, please report them to qt-
145 bugs@trolltech.com. Please include the name of the manual page
146 (qvalidator.3qt) and the Qt version (3.3.8).
147
148
149
150Trolltech AS 2 February 2007 QValidator(3qt)