[190] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/widgets/qvalidator.cpp:44 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>QValidator Class</title>
|
---|
| 7 | <style type="text/css"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { background: #ffffff; color: black; }
|
---|
| 12 | --></style>
|
---|
| 13 | </head>
|
---|
| 14 | <body>
|
---|
| 15 |
|
---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
| 17 | <tr bgcolor="#E5E5E5">
|
---|
| 18 | <td valign=center>
|
---|
| 19 | <a href="index.html">
|
---|
| 20 | <font color="#004faf">Home</font></a>
|
---|
| 21 | | <a href="classes.html">
|
---|
| 22 | <font color="#004faf">All Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main Classes</font></a>
|
---|
| 25 | | <a href="annotated.html">
|
---|
| 26 | <font color="#004faf">Annotated</font></a>
|
---|
| 27 | | <a href="groups.html">
|
---|
| 28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
| 29 | | <a href="functions.html">
|
---|
| 30 | <font color="#004faf">Functions</font></a>
|
---|
| 31 | </td>
|
---|
| 32 | <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>
|
---|
| 33 |
|
---|
| 34 | <p>The QValidator class provides validation of input text.
|
---|
| 35 | <a href="#details">More...</a>
|
---|
| 36 | <p><tt>#include <<a href="qvalidator-h.html">qvalidator.h</a>></tt>
|
---|
| 37 | <p>Inherits <a href="qobject.html">QObject</a>.
|
---|
| 38 | <p>Inherited by <a href="qintvalidator.html">QIntValidator</a>, <a href="qdoublevalidator.html">QDoubleValidator</a>, and <a href="qregexpvalidator.html">QRegExpValidator</a>.
|
---|
| 39 | <p><a href="qvalidator-members.html">List of all member functions.</a>
|
---|
| 40 | <h2>Public Members</h2>
|
---|
| 41 | <ul>
|
---|
| 42 | <li class=fn><a href="#QValidator"><b>QValidator</b></a> ( QObject * parent, const char * name = 0 )</li>
|
---|
| 43 | <li class=fn><a href="#~QValidator"><b>~QValidator</b></a> ()</li>
|
---|
| 44 | <li class=fn>enum <a href="#State-enum"><b>State</b></a> { Invalid, Intermediate, Valid = Intermediate, Acceptable }</li>
|
---|
| 45 | <li class=fn>virtual State <a href="#validate"><b>validate</b></a> ( QString & input, int & pos ) const = 0</li>
|
---|
| 46 | <li class=fn>virtual void <a href="#fixup"><b>fixup</b></a> ( QString & input ) const</li>
|
---|
| 47 | </ul>
|
---|
| 48 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | The QValidator class provides validation of input text.
|
---|
| 52 | <p>
|
---|
| 53 |
|
---|
| 54 | <p> The class itself is abstract. Two subclasses, <a href="qintvalidator.html">QIntValidator</a> and
|
---|
| 55 | <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>.
|
---|
| 56 | <p> If the built-in validators aren't sufficient, you can subclass
|
---|
| 57 | QValidator. The class has two virtual functions: <a href="#validate">validate</a>() and
|
---|
| 58 | <a href="#fixup">fixup</a>().
|
---|
| 59 | <p> <a href="#validate">validate</a>() must be implemented by every subclass. It returns
|
---|
| 60 | <a href="#State-enum">Invalid</a>, <a href="#State-enum">Intermediate</a> or <a href="#State-enum">Acceptable</a> depending on whether
|
---|
| 61 | its argument is valid (for the subclass's definition of valid).
|
---|
| 62 | <p> These three states require some explanation. An <a href="#State-enum">Invalid</a> string
|
---|
| 63 | is <em>clearly</em> invalid. <a href="#State-enum">Intermediate</a> is less obvious: the
|
---|
| 64 | concept of validity is slippery when the string is incomplete
|
---|
| 65 | (still being edited). QValidator defines <a href="#State-enum">Intermediate</a> as the
|
---|
| 66 | property of a string that is neither clearly invalid nor
|
---|
| 67 | acceptable as a final result. <a href="#State-enum">Acceptable</a> means that the string
|
---|
| 68 | is acceptable as a final result. One might say that any string
|
---|
| 69 | that is a plausible intermediate state during entry of an <a href="#State-enum">Acceptable</a> string is <a href="#State-enum">Intermediate</a>.
|
---|
| 70 | <p> Here are some examples:
|
---|
| 71 | <p> <ul>
|
---|
| 72 | <p> <li> For a line edit that accepts integers from 0 to 999 inclusive,
|
---|
| 73 | 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>.
|
---|
| 74 | <p> <li> For an editable combobox that accepts URLs, any well-formed URL
|
---|
| 75 | is <a href="#State-enum">Acceptable</a>, "http://www.trolltech.com/," is <a href="#State-enum">Intermediate</a>
|
---|
| 76 | (it might be a cut and paste operation that accidentally took in a
|
---|
| 77 | comma at the end), the empty string is <a href="#State-enum">Intermediate</a> (the user
|
---|
| 78 | might select and delete all of the text in preparation for entering
|
---|
| 79 | a new URL), and "http:///./" is <a href="#State-enum">Invalid</a>.
|
---|
| 80 | <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
|
---|
| 81 | "http://www.trolltech.com" and "hour" are <a href="#State-enum">Invalid</a>.
|
---|
| 82 | <p> </ul>
|
---|
| 83 | <p> <a href="#fixup">fixup</a>() is provided for validators that can repair some user
|
---|
| 84 | errors. The default implementation does nothing. <a href="qlineedit.html">QLineEdit</a>, for
|
---|
| 85 | example, will call <a href="#fixup">fixup</a>() if the user presses Enter (or Return)
|
---|
| 86 | and the content is not currently valid. This allows the fixup()
|
---|
| 87 | function the opportunity of performing some magic to make an <a href="#State-enum">Invalid</a> string <a href="#State-enum">Acceptable</a>.
|
---|
| 88 | <p> QValidator is typically used with QLineEdit, <a href="qspinbox.html">QSpinBox</a> and
|
---|
| 89 | <a href="qcombobox.html">QComboBox</a>.
|
---|
| 90 | <p>See also <a href="misc.html">Miscellaneous Classes</a>.
|
---|
| 91 |
|
---|
| 92 | <hr><h2>Member Type Documentation</h2>
|
---|
| 93 | <h3 class=fn><a name="State-enum"></a>QValidator::State</h3>
|
---|
| 94 |
|
---|
| 95 | <p> This enum type defines the states in which a validated string can
|
---|
| 96 | exist.
|
---|
| 97 | <ul>
|
---|
| 98 | <li><tt>QValidator::Invalid</tt> - the string is <em>clearly</em> invalid.
|
---|
| 99 | <li><tt>QValidator::Intermediate</tt> - the string is a plausible intermediate value
|
---|
| 100 | during editing.
|
---|
| 101 | <li><tt>QValidator::Acceptable</tt> - the string is acceptable as a final result,
|
---|
| 102 | i.e. it is valid.
|
---|
| 103 | </ul>
|
---|
| 104 | <hr><h2>Member Function Documentation</h2>
|
---|
| 105 | <h3 class=fn><a name="QValidator"></a>QValidator::QValidator ( <a href="qobject.html">QObject</a> * parent, const char * name = 0 )
|
---|
| 106 | </h3>
|
---|
| 107 | Sets up the validator. The <em>parent</em> and <em>name</em> parameters are
|
---|
| 108 | passed on to the <a href="qobject.html">QObject</a> constructor.
|
---|
| 109 |
|
---|
| 110 | <h3 class=fn><a name="~QValidator"></a>QValidator::~QValidator ()
|
---|
| 111 | </h3>
|
---|
| 112 | Destroys the validator, freeing any storage and other resources
|
---|
| 113 | used.
|
---|
| 114 |
|
---|
| 115 | <h3 class=fn>void <a name="fixup"></a>QValidator::fixup ( <a href="qstring.html">QString</a> & input ) const<tt> [virtual]</tt>
|
---|
| 116 | </h3>
|
---|
| 117 |
|
---|
| 118 | <p> This function attempts to change <em>input</em> to be valid according to
|
---|
| 119 | this validator's rules. It need not result in a valid string:
|
---|
| 120 | callers of this function must re-test afterwards; the default does
|
---|
| 121 | nothing.
|
---|
| 122 | <p> Reimplementations of this function can change <em>input</em> even if
|
---|
| 123 | they do not produce a valid string. For example, an ISBN validator
|
---|
| 124 | might want to delete every character except digits and "-", even
|
---|
| 125 | if the result is still not a valid ISBN; a surname validator might
|
---|
| 126 | want to remove whitespace from the start and end of the string,
|
---|
| 127 | even if the resulting string is not in the list of accepted
|
---|
| 128 | surnames.
|
---|
| 129 |
|
---|
| 130 | <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>
|
---|
| 131 | </h3>
|
---|
| 132 |
|
---|
| 133 | <p> This pure virtual function returns <a href="#State-enum">Invalid</a> if <em>input</em> is
|
---|
| 134 | invalid according to this validator's rules, <a href="#State-enum">Intermediate</a> if it
|
---|
| 135 | is likely that a little more editing will make the input
|
---|
| 136 | acceptable (e.g. the user types '4' into a widget which accepts
|
---|
| 137 | integers between 10 and 99) and <a href="#State-enum">Acceptable</a> if the input is
|
---|
| 138 | valid.
|
---|
| 139 | <p> The function can change <em>input</em> and <em>pos</em> (the cursor position)
|
---|
| 140 | if it wants to.
|
---|
| 141 |
|
---|
| 142 | <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>.
|
---|
| 143 | <!-- eof -->
|
---|
| 144 | <hr><p>
|
---|
| 145 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 146 | Copyright © 1995-2007
|
---|
| 147 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
| 148 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 149 | <td>Copyright © 2007
|
---|
| 150 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 151 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 152 | </table></div></address></body>
|
---|
| 153 | </html>
|
---|