summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqvalidator.3qt
blob: 40aaf0ab17dc76341d4f54ea738587f5afeb7321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'\" t
.TH QValidator 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QValidator \- Validation of input text
.SH SYNOPSIS
\fC#include <ntqvalidator.h>\fR
.PP
Inherits QObject.
.PP
Inherited by QIntValidator, QDoubleValidator, and QRegExpValidator.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQValidator\fR ( QObject * parent, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QValidator\fR ()"
.br
.ti -1c
.BI "enum \fBState\fR { Invalid, Intermediate, Valid = Intermediate, Acceptable }"
.br
.ti -1c
.BI "virtual State \fBvalidate\fR ( QString & input, int & pos ) const = 0"
.br
.ti -1c
.BI "virtual void \fBfixup\fR ( QString & input ) const"
.br
.in -1c
.SH DESCRIPTION
The QValidator class provides validation of input text.
.PP
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.
.PP
If the built-in validators aren't sufficient, you can subclass QValidator. The class has two virtual functions: validate() and fixup().
.PP
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).
.PP
These three states require some explanation. An Invalid string is \fIclearly\fR invalid. Intermediate is less obvious: the concept of validity is slippery 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.
.PP
Here are some examples:
.IP
.TP
For a line edit that accepts integers from 0 to 999 inclusive, 42 and 123 are Acceptable, the empty string and 1114 are Intermediate and asdf is Invalid.
.IP
.TP
For an editable combobox that accepts URLs, any well-formed URL is Acceptable, "http://www.trolltech.com/," is Intermediate (it might be a cut and paste operation that accidentally took in a comma at the end), the empty string is Intermediate (the user might select and delete all of the text in preparation for entering a new URL), and "http:///./" is Invalid.
.IP
.TP
For a spin box that accepts lengths, "11cm" and "1in" are Acceptable, "11" and the empty string are Intermediate and" http://www.trolltech.com" and "hour" are Invalid.
.IP
.PP
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.
.PP
QValidator is typically used with QLineEdit, QSpinBox and QComboBox.
.PP
See also Miscellaneous Classes.
.SS "Member Type Documentation"
.SH "QValidator::State"
This enum type defines the states in which a validated string can exist.
.TP
\fCQValidator::Invalid\fR - the string is \fIclearly\fR invalid.
.TP
\fCQValidator::Intermediate\fR - the string is a plausible intermediate value during editing.
.TP
\fCQValidator::Acceptable\fR - the string is acceptable as a final result, i.e. it is valid.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QValidator::QValidator ( QObject * parent, const char * name = 0 )"
Sets up the validator. The \fIparent\fR and \fIname\fR parameters are passed on to the QObject constructor.
.SH "QValidator::~QValidator ()"
Destroys the validator, freeing any storage and other resources used.
.SH "void QValidator::fixup ( QString & input ) const\fC [virtual]\fR"
This function attempts to change \fIinput\fR to be valid according to this validator's rules. It need not result in a valid string: callers of this function must re-test afterwards; the default does nothing.
.PP
Reimplementations of this function can change \fIinput\fR even if they do not produce a valid string. For example, an ISBN validator might want to delete every character except digits and "-", even if the result is still not a valid ISBN; a surname validator might want to remove whitespace from the start and end of the string, even if the resulting string is not in the list of accepted surnames.
.SH "State QValidator::validate ( QString & input, int & pos ) const\fC [pure virtual]\fR"
This pure virtual function returns Invalid if \fIinput\fR is invalid according to this validator's rules, Intermediate if it is likely that a little more editing will make the input acceptable (e.g. the user types '4' into a widget which accepts integers between 10 and 99) and Acceptable if the input is valid.
.PP
The function can change \fIinput\fR and \fIpos\fR (the cursor position) if it wants to.
.PP
Reimplemented in QIntValidator, QDoubleValidator, and QRegExpValidator.

.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqvalidator.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqvalidator.3qt) and the Qt
version (3.3.8).