1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/gui/widgets/qvalidator.cpp -->
7
<title>Qt 4.0: QValidator Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<td width="1"> </td><td class="postheader" 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>
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QValidator Class Reference</h1>
21
<p>The QValidator class provides validation of input text. <a href="#details">More...</a></p>
22
<pre>#include <QValidator></pre><p>Part of the <a href="qtgui.html">QtGui</a> module.</p>
23
<p>Inherits <a href="qobject.html">QObject</a>.</p>
24
<p>Inherited by <a href="qdoublevalidator.html">QDoubleValidator</a>, <a href="qintvalidator.html">QIntValidator</a>, and <a href="qregexpvalidator.html">QRegExpValidator</a>.</p>
26
<li><a href="qvalidator-members.html">List of all members, including inherited members</a></li>
27
<li><a href="qvalidator-qt3.html">Qt 3 support members</a></li>
29
<a name="public-types"></a>
32
<li><div class="fn"/>enum <b><a href="qvalidator.html#State-enum">State</a></b> { Invalid, Intermediate, Acceptable }</li>
34
<a name="public-functions"></a>
35
<h3>Public Functions</h3>
37
<li><div class="fn"/><b><a href="qvalidator.html#QValidator">QValidator</a></b> ( QObject * <i>parent</i> )</li>
38
<li><div class="fn"/><b><a href="qvalidator.html#dtor.QValidator">~QValidator</a></b> ()</li>
39
<li><div class="fn"/>virtual void <b><a href="qvalidator.html#fixup">fixup</a></b> ( QString & <i>input</i> ) const</li>
40
<li><div class="fn"/>virtual State <b><a href="qvalidator.html#validate">validate</a></b> ( QString & <i>input</i>, int & <i>pos</i> ) const = 0</li>
43
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
45
<h3>Additional Inherited Members</h3>
47
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
48
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
49
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
50
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
51
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
53
<a name="details"></a>
55
<h2>Detailed Description</h2>
56
<p>The QValidator class provides validation of input text.</p>
57
<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 regular expression.</p>
58
<p>If the built-in validators aren't sufficient, you can subclass QValidator. The class has two virtual functions: <a href="qvalidator.html#validate">validate</a>() and <a href="qvalidator.html#fixup">fixup</a>().</p>
59
<p><a href="qvalidator.html#validate">validate</a>() must be implemented by every subclass. It returns <tt>Invalid</tt>, <tt>Intermediate</tt> or <tt>Acceptable</tt> depending on whether its argument is valid (for the subclass's definition of valid).</p>
60
<p>These three states require some explanation. An <tt>Invalid</tt> string is <i>clearly</i> invalid. <tt>Intermediate</tt> is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). QValidator defines <tt>Intermediate</tt> as the property of a string that is neither clearly invalid nor acceptable as a final result. <tt>Acceptable</tt> 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 <tt>Acceptable</tt> string is <tt>Intermediate</tt>.</p>
61
<p>Here are some examples:</p>
63
<li>For a line edit that accepts integers from 10 to 999 inclusive, 42 and 123 are <tt>Acceptable</tt>, the empty string and 5 are <tt>Intermediate</tt>, and "asdf" and 1114 is <tt>Invalid</tt>.</li>
64
<li>For an editable combobox that accepts URLs, any well-formed URL is <tt>Acceptable</tt>, "http://www.trolltech.com/," is <tt>Intermediate</tt> (it might be a cut and paste action that accidentally took in a comma at the end), the empty string is <tt>Intermediate</tt> (the user might select and delete all of the text in preparation for entering a new URL) and "http:///./" is <tt>Invalid</tt>.</li>
65
<li>For a spin box that accepts lengths, "11cm" and "1in" are <tt>Acceptable</tt>, "11" and the empty string are <tt>Intermediate</tt>, and "http://www.trolltech.com" and "hour" are <tt>Invalid</tt>.</li>
67
<p><a href="qvalidator.html#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="qvalidator.html#fixup">fixup</a>() if the user presses Enter (or Return) and the content is not currently valid. This allows the <a href="qvalidator.html#fixup">fixup</a>() function the opportunity of performing some magic to make an <tt>Invalid</tt> string <tt>Acceptable</tt>.</p>
68
<p>QValidator is typically used with <a href="qlineedit.html">QLineEdit</a>, <a href="qspinbox.html">QSpinBox</a> and <a href="qcombobox.html">QComboBox</a>.</p>
70
<h2>Member Type Documentation</h2>
71
<h3 class="fn"><a name="State-enum"></a>enum QValidator::State</h3>
72
<p>This enum type defines the states in which a validated string can exist.</p>
73
<table border="1" cellpadding="2" cellspacing="1" width="100%">
74
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
75
<tr><td valign="top"><tt>QValidator::Invalid</tt></td><td align="center" valign="top"><tt>0</tt></td><td valign="top">The string is <i>clearly</i> invalid.</td></tr>
76
<tr><td valign="top"><tt>QValidator::Intermediate</tt></td><td align="center" valign="top"><tt>1</tt></td><td valign="top">The string is a plausible intermediate value during editing.</td></tr>
77
<tr><td valign="top"><tt>QValidator::Acceptable</tt></td><td align="center" valign="top"> </td><td valign="top">The string is acceptable as a final result; i.e. it is valid.</td></tr>
80
<h2>Member Function Documentation</h2>
81
<h3 class="fn"><a name="QValidator"></a>QValidator::QValidator ( <a href="qobject.html">QObject</a> * <i>parent</i> )</h3>
82
<p>Sets up the validator. The <i>parent</i> parameter is passed on to the <a href="qobject.html">QObject</a> constructor.</p>
83
<h3 class="fn"><a name="dtor.QValidator"></a>QValidator::~QValidator ()</h3>
84
<p>Destroys the validator, freeing any storage and other resources used.</p>
85
<h3 class="fn"><a name="fixup"></a>void QValidator::fixup ( <a href="qstring.html">QString</a> & <i>input</i> ) const <tt> [virtual]</tt></h3>
86
<p>This function attempts to change <i>input</i> 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>
87
<p>Reimplementations of this function can change <i>input</i> 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.</p>
88
<h3 class="fn"><a name="validate"></a><a href="qvalidator.html#State-enum">State</a> QValidator::validate ( <a href="qstring.html">QString</a> & <i>input</i>, int & <i>pos</i> ) const <tt> [pure virtual]</tt></h3>
89
<p>This virtual function returns <tt>Invalid</tt> if <i>input</i> is invalid according to this validator's rules, <tt>Intermediate</tt> 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 <tt>Acceptable</tt> if the input is valid.</p>
90
<p>The function can change both <i>input</i> and <i>pos</i> (the cursor position) if required.</p>
91
<p /><address><hr /><div align="center">
92
<table width="100%" cellspacing="0" border="0"><tr class="address">
93
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
94
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
95
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
96
</tr></table></div></address></body>