File: qvalidator.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (129 lines) | stat: -rw-r--r-- 7,656 bytes parent folder | download
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QValidator Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">

<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>

<h1 align=center>QValidator Class Reference</h1><br clear="all">
<p>
The QValidator class provides validation of input text.
<a href="#details">More...</a>
<p>
<code>#include &lt;<a href="qvalidator-h.html">qvalidator.h</a>&gt;</code>
<p>
Inherits <a href="qobject.html">QObject</a>.
<p>Inherited by <a href="qdoublevalidator.html">QDoubleValidator</a> and <a href="qintvalidator.html">QIntValidator</a>.
<p><a href="qvalidator-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#0b5d7d"><b>QValidator</b></a>(QWidget*parent, constchar*name=0)</div>
<li><div class="fn"><a href="#3baeb0"><b>~QValidator</b></a>()</div>
<li><div class="fn">enum<a href="#State"><b>State</b></a>{Invalid, Intermediate, Valid=Intermediate, Acceptable}</div>
<li><div class="fn">virtualState<a href="#da4f8c"><b>validate</b></a>(QString&amp;, int&amp;)const</div>
<li><div class="fn">virtualvoid<a href="#3fa523"><b>fixup</b></a>(QString&amp;)const</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QValidator class provides validation of input text.
<p>
The class itself is abstract; two subclasses provide rudimentary
numeric range checking.
<p>The class includes two virtual functions, <a href="#da4f8c">validate</a>() and <a href="#3fa523">fixup</a>().
<p>validate() is pure virtual, so it must be implemented by every
subclass.  It returns <code>Invalid, Intermediate</code> or <code>Acceptable</code>
depending on whether its argument is valid (for the class'
definition of valid).
<p>The three states require some explanation.  An <code>Invalid</code> string is
<em>clearly</em> invalid.  <code>Intermediate</code> is less obvious - the concept
of validity is slippery when the string is incomplete (still being
edited).  QValidator defines <code>Intermediate</code> as the property of a
string that it is neither clearly invalid or acceptable as a final
result.  <code>Acceptable</code> 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 <code>Acceptable</code> string is <code>Intermediate.</code>
<p>Here are some examples:
<ol>
<li>For a line edit that accepts integers from 0 to 999 inclusive,
42 and 666 are <code>Acceptable,</code> the empty string and 1114 are <code>Intermediate</code> and asdf is <code>Invalid.</code>
<li>For an editable combo box that accepts URLs, any well-formed URL
is <code>Acceptable,</code> "http://www.trolltech.com/," is <code>Intermediate</code> (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:///./" is <code>Invalid.</code>
<li>For a spin box that accepts lengths, "11cm" and "1in" are <code>Acceptable,</code> "11" and the empty string are <code>Intermediate,</code> and
"http://www.trolltech.com" and "hour" are <code>Invalid.</code>
<p></ol>
<p>fixup() is provided for validators that can repair some or all user
errors.  The default does nothing.  <a href="qlineedit.html">QLineEdit</a>, 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 <code>Invalid</code> strings to be made <code>Acceptable,</code> too, spoiling the muddy
definition above even more.
<p>QValidator is generally used with QLineEdit, <a href="qspinbox.html">QSpinBox</a> and <a href="qcombobox.html">QComboBox</a>.

<hr><h2>Member Type Documentation</h2>
<h3 class="fn"><a name="State">QValidator::State</a></h3>
This enum type defines the states in which a validated string can
be.  There are currently three states: <ul>
<li> <code>Invalid</code> - the string is <em>clearly</em> invalid.
<li> <code>Intermediate</code> - the string is a plausible intermediate value
during editing.
<li> <code>Acceptable</code> - acceptable as a final result.
<p></ul>
<p>The state <code>Valid</code> has been renamed <code>Intermediate.</code>  The old name
confused too many people and is now obsolete.
<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="0b5d7d"></a>QValidator::QValidator(<a href="qwidget.html">QWidget</a>*parent, constchar*name=0)</h3>
<p>Sets up the internal data structures used by the validator.  At
the moment there aren't any.
<h3 class="fn"><a name="3baeb0"></a>QValidator::~QValidator()</h3>
<p>Destroys the validator, freeing any storage and other resources
used.
<h3 class="fn">void<a name="3fa523"></a>QValidator::fixup(<a href="qstring.html">QString</a>&amp;input)const <code>[virtual]</code></h3>
<p>Attempts to change <em>input</em> 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.
<p>Reimplementations of this function can change <em>input</em> 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 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.
<h3 class="fn">QValidator::State<a name="da4f8c"></a>QValidator::validate(QString&input, int&pos)const</h3>
<p>This pure virtual function returns <code>Invalid</code> if <em>input</em> is invalid
according to this validator's rules, <code>Intermediate</code> 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 10-99) and <code>Acceptable</code> if
the input is completely acceptable.
<p>The function can change <em>input</em> and <em>pos</em> (the cursor position) if
it wants to.
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright &copy; 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>