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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/harald/tmp/qt-3.3.7-harald-4508/qt-x11-free-3.3.7/src/widgets/qvalidator.cpp:44 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QValidator Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QValidator Class Reference</h1>
<p>The QValidator class provides validation of input text.
<a href="#details">More...</a>
<p><tt>#include <<a href="qvalidator-h.html">qvalidator.h</a>></tt>
<p>Inherits <a href="qobject.html">QObject</a>.
<p>Inherited by <a href="qintvalidator.html">QIntValidator</a>, <a href="qdoublevalidator.html">QDoubleValidator</a>, and <a href="qregexpvalidator.html">QRegExpValidator</a>.
<p><a href="qvalidator-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QValidator"><b>QValidator</b></a> ( QObject * parent, const char * name = 0 )</li>
<li class=fn><a href="#~QValidator"><b>~QValidator</b></a> ()</li>
<li class=fn>enum <a href="#State-enum"><b>State</b></a> { Invalid, Intermediate, Valid = Intermediate, Acceptable }</li>
<li class=fn>virtual State <a href="#validate"><b>validate</b></a> ( QString & input, int & pos ) const = 0</li>
<li class=fn>virtual void <a href="#fixup"><b>fixup</b></a> ( QString & input ) const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
The QValidator class provides validation of input text.
<p>
<p> The class itself is abstract. Two subclasses, <a href="qintvalidator.html">QIntValidator</a> and
<a href="qdoublevalidator.html">QDoubleValidator</a>, provide basic numeric-range checking, and <a href="qregexpvalidator.html">QRegExpValidator</a> provides general checking using a custom <a href="qregexp.html#regular-expression">regular expression</a>.
<p> If the built-in validators aren't sufficient, you can subclass
QValidator. The class has two virtual functions: <a href="#validate">validate</a>() and
<a href="#fixup">fixup</a>().
<p> <a href="#validate">validate</a>() must be implemented by every subclass. It returns
<a href="#State-enum">Invalid</a>, <a href="#State-enum">Intermediate</a> or <a href="#State-enum">Acceptable</a> depending on whether
its argument is valid (for the subclass's definition of valid).
<p> These three states require some explanation. An <a href="#State-enum">Invalid</a> string
is <em>clearly</em> invalid. <a href="#State-enum">Intermediate</a> is less obvious: the
concept of validity is slippery when the string is incomplete
(still being edited). QValidator defines <a href="#State-enum">Intermediate</a> as the
property of a string that is neither clearly invalid nor
acceptable as a final result. <a href="#State-enum">Acceptable</a> 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 <a href="#State-enum">Acceptable</a> string is <a href="#State-enum">Intermediate</a>.
<p> Here are some examples:
<p> <ul>
<p> <li> For a line edit that accepts integers from 0 to 999 inclusive,
42 and 123 are <a href="#State-enum">Acceptable</a>, the empty string and 1114 are <a href="#State-enum">Intermediate</a> and asdf is <a href="#State-enum">Invalid</a>.
<p> <li> For an editable combobox that accepts URLs, any well-formed URL
is <a href="#State-enum">Acceptable</a>, "http://www.trolltech.com/," is <a href="#State-enum">Intermediate</a>
(it might be a cut and paste operation that accidentally took in a
comma at the end), the empty string is <a href="#State-enum">Intermediate</a> (the user
might select and delete all of the text in preparation for entering
a new URL), and "http:///./" is <a href="#State-enum">Invalid</a>.
<p> <li> For a spin box that accepts lengths, "11cm" and "1in" are <a href="#State-enum">Acceptable</a>, "11" and the empty string are <a href="#State-enum">Intermediate</a> and
"http://www.trolltech.com" and "hour" are <a href="#State-enum">Invalid</a>.
<p> </ul>
<p> <a href="#fixup">fixup</a>() is provided for validators that can repair some user
errors. The default implementation does nothing. <a href="qlineedit.html">QLineEdit</a>, for
example, will call <a href="#fixup">fixup</a>() 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 <a href="#State-enum">Invalid</a> string <a href="#State-enum">Acceptable</a>.
<p> QValidator is typically used with QLineEdit, <a href="qspinbox.html">QSpinBox</a> and
<a href="qcombobox.html">QComboBox</a>.
<p>See also <a href="misc.html">Miscellaneous Classes</a>.
<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="State-enum"></a>QValidator::State</h3>
<p> This enum type defines the states in which a validated string can
exist.
<ul>
<li><tt>QValidator::Invalid</tt> - the string is <em>clearly</em> invalid.
<li><tt>QValidator::Intermediate</tt> - the string is a plausible intermediate value
during editing.
<li><tt>QValidator::Acceptable</tt> - the string is acceptable as a final result,
i.e. it is valid.
</ul>
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QValidator"></a>QValidator::QValidator ( <a href="qobject.html">QObject</a> * parent, const char * name = 0 )
</h3>
Sets up the validator. The <em>parent</em> and <em>name</em> parameters are
passed on to the <a href="qobject.html">QObject</a> constructor.
<h3 class=fn><a name="~QValidator"></a>QValidator::~QValidator ()
</h3>
Destroys the validator, freeing any storage and other resources
used.
<h3 class=fn>void <a name="fixup"></a>QValidator::fixup ( <a href="qstring.html">QString</a> & input ) const<tt> [virtual]</tt>
</h3>
<p> This function attempts to change <em>input</em> 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.
<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 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.
<h3 class=fn><a href="qvalidator.html#State-enum">State</a> <a name="validate"></a>QValidator::validate ( <a href="qstring.html">QString</a> & input, int & pos ) const<tt> [pure virtual]</tt>
</h3>
<p> This pure virtual function returns <a href="#State-enum">Invalid</a> if <em>input</em> is
invalid according to this validator's rules, <a href="#State-enum">Intermediate</a> 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 <a href="#State-enum">Acceptable</a> if the input is
valid.
<p> The function can change <em>input</em> and <em>pos</em> (the cursor position)
if it wants to.
<p>Reimplemented in <a href="qintvalidator.html#validate">QIntValidator</a>, <a href="qdoublevalidator.html#validate">QDoubleValidator</a>, and <a href="qregexpvalidator.html#validate">QRegExpValidator</a>.
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright © 1995-2005
<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 © 2005
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.7</div>
</table></div></address></body>
</html>
|