File: qvalidator.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (159 lines) | stat: -rw-r--r-- 14,301 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qvalidator.cpp -->
  <title>Qt 4.8: QValidator Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtgui.html">QtGui</a></li>
<li>QValidator</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QValidator Class Reference</h1>
<!-- $$$QValidator-brief -->
<p>The QValidator class provides validation of input text. <a href="#details">More...</a></p>
<!-- @@@QValidator -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QValidator&gt;</span></pre><p><b>Inherits: </b><a href="qobject.html">QObject</a>.</p>
<p><b>Inherited by: </b><a href="qdoublevalidator.html">QDoubleValidator</a>, <a href="qintvalidator.html">QIntValidator</a>, and <a href="qregexpvalidator.html">QRegExpValidator</a>.</p>
<ul>
<li><a href="qvalidator-members.html">List of all members, including inherited members</a></li>
<li><a href="qvalidator-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#State-enum">State</a></b> { Invalid, Intermediate, Acceptable }</td></tr>
</table>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#QValidator">QValidator</a></b> ( QObject * <i>parent</i> = 0 )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#dtor.QValidator">~QValidator</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#fixup">fixup</a></b> ( QString &amp; <i>input</i> ) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QLocale </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#locale">locale</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#setLocale">setLocale</a></b> ( const QLocale &amp; <i>locale</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual State </td><td class="memItemRight bottomAlign"><b><a href="qvalidator.html#validate">validate</a></b> ( QString &amp; <i>input</i>, int &amp; <i>pos</i> ) const = 0</td></tr>
</table>
<ul>
<li class="fn">29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li class="fn">7 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li class="fn">8 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QValidator-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>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 regular expression.</p>
<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>
<p><a href="qvalidator.html#validate">validate</a>() must be implemented by every subclass. It returns <a href="qvalidator.html#State-enum">Invalid</a>, <a href="qvalidator.html#State-enum">Intermediate</a> or <a href="qvalidator.html#State-enum">Acceptable</a> depending on whether its argument is valid (for the subclass's definition of valid).</p>
<p>These three states require some explanation. An <a href="qvalidator.html#State-enum">Invalid</a> string is <i>clearly</i> invalid. <a href="qvalidator.html#State-enum">Intermediate</a> is less obvious: the concept of validity is difficult to apply when the string is incomplete (still being edited). QValidator defines <a href="qvalidator.html#State-enum">Intermediate</a> as the property of a string that is neither clearly invalid nor acceptable as a final result. <a href="qvalidator.html#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="qvalidator.html#State-enum">Acceptable</a> string is <a href="qvalidator.html#State-enum">Intermediate</a>.</p>
<p>Here are some examples:</p>
<ul>
<li>For a line edit that accepts integers from 10 to 1000 inclusive, 42 and 123 are <a href="qvalidator.html#State-enum">Acceptable</a>, the empty string and 5 are <a href="qvalidator.html#State-enum">Intermediate</a>, and &quot;asdf&quot; and 1114 is <a href="qvalidator.html#State-enum">Invalid</a>.</li>
<li>For an editable combobox that accepts URLs, any well-formed URL is <a href="qvalidator.html#State-enum">Acceptable</a>, &quot;http://example.com/,&quot; is <a href="qvalidator.html#State-enum">Intermediate</a> (it might be a cut and paste action that accidentally took in a comma at the end), the empty string is <a href="qvalidator.html#State-enum">Intermediate</a> (the user might select and delete all of the text in preparation for entering a new URL) and &quot;http:///./&quot; is <a href="qvalidator.html#State-enum">Invalid</a>.</li>
<li>For a spin box that accepts lengths, &quot;11cm&quot; and &quot;1in&quot; are <a href="qvalidator.html#State-enum">Acceptable</a>, &quot;11&quot; and the empty string are <a href="qvalidator.html#State-enum">Intermediate</a>, and &quot;http://example.com&quot; and &quot;hour&quot; are <a href="qvalidator.html#State-enum">Invalid</a>.</li>
</ul>
<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 <a href="qvalidator.html#State-enum">Invalid</a> string <a href="qvalidator.html#State-enum">Acceptable</a>.</p>
<p>A validator has a locale, set with <a href="qvalidator.html#setLocale">setLocale</a>(). It is typically used to parse localized data. For example, <a href="qintvalidator.html">QIntValidator</a> and <a href="qdoublevalidator.html">QDoubleValidator</a> use it to parse localized representations of integers and doubles.</p>
<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>
</div>
<p><b>See also </b><a href="qintvalidator.html">QIntValidator</a>, <a href="qdoublevalidator.html">QDoubleValidator</a>, <a href="qregexpvalidator.html">QRegExpValidator</a>, and <a href="widgets-lineedits.html">Line Edits Example</a>.</p>
<!-- @@@QValidator -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$State$$$Invalid$$$Intermediate$$$Acceptable$$$Valid -->
<h3 class="fn"><a name="State-enum"></a>enum QValidator::<span class="name">State</span></h3>
<p>This enum type defines the states in which a validated string can exist.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QValidator::Invalid</tt></td><td class="topAlign"><tt>0</tt></td><td class="topAlign">The string is <i>clearly</i> invalid.</td></tr>
<tr><td class="topAlign"><tt>QValidator::Intermediate</tt></td><td class="topAlign"><tt>1</tt></td><td class="topAlign">The string is a plausible intermediate value.</td></tr>
<tr><td class="topAlign"><tt>QValidator::Acceptable</tt></td><td class="topAlign"><tt>2</tt></td><td class="topAlign">The string is acceptable as a final result; i.e&#x2e; it is valid.</td></tr>
</table>
<!-- @@@State -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QValidator[overload1]$$$QValidatorQObject* -->
<h3 class="fn"><a name="QValidator"></a>QValidator::<span class="name">QValidator</span> ( <span class="type"><a href="qobject.html">QObject</a></span> * <i>parent</i> = 0 )</h3>
<p>Sets up the validator. The <i>parent</i> parameter is passed on to the <a href="qobject.html">QObject</a> constructor.</p>
<!-- @@@QValidator -->
<!-- $$$~QValidator[overload1]$$$~QValidator -->
<h3 class="fn"><a name="dtor.QValidator"></a>QValidator::<span class="name">~QValidator</span> ()</h3>
<p>Destroys the validator, freeing any storage and other resources used.</p>
<!-- @@@~QValidator -->
<!-- $$$fixup[overload1]$$$fixupQString& -->
<h3 class="fn"><a name="fixup"></a><span class="type">void</span> QValidator::<span class="name">fixup</span> ( <span class="type"><a href="qstring.html">QString</a></span> &amp; <i>input</i> ) const<tt> [virtual]</tt></h3>
<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>
<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 &quot;-&quot;, 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>
<!-- @@@fixup -->
<!-- $$$locale[overload1]$$$locale -->
<h3 class="fn"><a name="locale"></a><span class="type"><a href="qlocale.html">QLocale</a></span> QValidator::<span class="name">locale</span> () const</h3>
<p>Returns the locale for the validator. The locale is by default initialized to the same as QLocale().</p>
<p><b>See also </b><a href="qvalidator.html#setLocale">setLocale</a>() and <a href="qlocale.html#QLocale">QLocale::QLocale</a>().</p>
<!-- @@@locale -->
<!-- $$$setLocale[overload1]$$$setLocaleconstQLocale& -->
<h3 class="fn"><a name="setLocale"></a><span class="type">void</span> QValidator::<span class="name">setLocale</span> ( const <span class="type"><a href="qlocale.html">QLocale</a></span> &amp; <i>locale</i> )</h3>
<p>Sets the <i>locale</i> that will be used for the validator. Unless setLocale has been called, the validator will use the default locale set with <a href="qlocale.html#setDefault">QLocale::setDefault</a>(). If a default locale has not been set, it is the operating system's locale.</p>
<p><b>See also </b><a href="qvalidator.html#locale">locale</a>() and <a href="qlocale.html#setDefault">QLocale::setDefault</a>().</p>
<!-- @@@setLocale -->
<!-- $$$validate[overload1]$$$validateQString&int& -->
<h3 class="fn"><a name="validate"></a><span class="type"><a href="qvalidator.html#State-enum">State</a></span> QValidator::<span class="name">validate</span> ( <span class="type"><a href="qstring.html">QString</a></span> &amp; <i>input</i>, <span class="type">int</span> &amp; <i>pos</i> ) const<tt> [pure virtual]</tt></h3>
<p>This virtual function returns <a href="qvalidator.html#State-enum">Invalid</a> if <i>input</i> is invalid according to this validator's rules, <a href="qvalidator.html#State-enum">Intermediate</a> if it is likely that a little more editing will make the input acceptable (e.g&#x2e; the user types &quot;4&quot; into a widget which accepts integers between 10 and 99), and <a href="qvalidator.html#State-enum">Acceptable</a> if the input is valid.</p>
<p>The function can change both <i>input</i> and <i>pos</i> (the cursor position) if required.</p>
<!-- @@@validate -->
</div>
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>