<?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/style.css" /> <script src="scripts/jquery.js" type="text/javascript"></script> <script src="scripts/functions.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="style/superfish.css" /> <link rel="stylesheet" type="text/css" href="style/narrow.css" /> <!--[if IE]> <meta name="MSSmartTagsPreventParsing" content="true"> <meta http-equiv="imagetoolbar" content="no"> <![endif]--> <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="style/style_ie6.css"> <![endif]--> <!--[if IE 7]> <link rel="stylesheet" type="text/css" href="style/style_ie7.css"> <![endif]--> <!--[if IE 8]> <link rel="stylesheet" type="text/css" href="style/style_ie8.css"> <![endif]--> <script src="scripts/superfish.js" type="text/javascript"></script> <script src="scripts/narrow.js" type="text/javascript"></script> </head> <body class="" onload="CheckEmptyAndLoadList();"> <div class="header" id="qtdocheader"> <div class="content"> <div id="nav-logo"> <a href="index.html">Home</a></div> <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a> <div id="narrowsearch"></div> <div id="nav-topright"> <ul> <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li> <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li> <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/"> DOC</a></li> <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li> </ul> </div> <div id="shortCut"> <ul> <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li> <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS </a></li> </ul> </div> <ul class="sf-menu" id="narrowmenu"> <li><a href="#">API Lookup</a> <ul> <li><a href="classes.html">Class index</a></li> <li><a href="functions.html">Function index</a></li> <li><a href="modules.html">Modules</a></li> <li><a href="namespaces.html">Namespaces</a></li> <li><a href="qtglobal.html">Global Declarations</a></li> <li><a href="qdeclarativeelements.html">QML elements</a></li> </ul> </li> <li><a href="#">Qt Topics</a> <ul> <li><a href="qt-basic-concepts.html">Programming with Qt</a></li> <li><a href="qtquick.html">Device UIs & Qt Quick</a></li> <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li> <li><a href="supported-platforms.html">Supported Platforms</a></li> <li><a href="technology-apis.html">Qt and Key Technologies</a></li> <li><a href="best-practices.html">How-To's and Best Practices</a></li> </ul> </li> <li><a href="#">Examples</a> <ul> <li><a href="all-examples.html">Examples</a></li> <li><a href="tutorials.html">Tutorials</a></li> <li><a href="demos.html">Demos</a></li> <li><a href="qdeclarativeexamples.html">QML Examples</a></li> </ul> </li> </ul> </div> </div> <div class="wrapper"> <div class="hd"> <span></span> </div> <div class="bd group"> <div class="sidebar"> <div class="searchlabel"> Search index:</div> <div class="search" id="sidebarsearch"> <form id="qtdocsearch" action="" onsubmit="return false;"> <fieldset> <input type="text" name="searchstring" id="pageType" value="" /> <div id="resultdialog"> <a href="#" id="resultclose">Close</a> <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span> results:</p> <ul id="resultlist" class="all"> </ul> </div> </fieldset> </form> </div> <div class="box first bottombar" id="lookup"> <h2 title="API Lookup"><span></span> API Lookup</h2> <div id="list001" class="list"> <ul id="ul001" > <li class="defaultLink"><a href="classes.html">Class index</a></li> <li class="defaultLink"><a href="functions.html">Function index</a></li> <li class="defaultLink"><a href="modules.html">Modules</a></li> <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li> <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li> <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li> </ul> </div> </div> <div class="box bottombar" id="topics"> <h2 title="Qt Topics"><span></span> Qt Topics</h2> <div id="list002" class="list"> <ul id="ul002" > <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> <li class="defaultLink"><a href="qtquick.html">Device UIs & Qt Quick</a></li> <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li> <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> </ul> </div> </div> <div class="box" id="examples"> <h2 title="Examples"><span></span> Examples</h2> <div id="list003" class="list"> <ul id="ul003"> <li class="defaultLink"><a href="all-examples.html">Examples</a></li> <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li> <li class="defaultLink"><a href="demos.html">Demos</a></li> <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li> </ul> </div> </div> </div> <div class="wrap"> <div class="toolbar"> <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 class="toolbuttons toolblock"> <ul> <li id="smallA" class="t_button">A</li> <li id="medA" class="t_button active">A</li> <li id="bigA" class="t_button">A</li> <li id="print" class="t_button"><a href="javascript:this.print();"> <span>Print</span></a></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 <QValidator></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 & <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 & <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 & <i>input</i>, int & <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 "asdf" 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>, "http://example.com/," 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 "http:///./" is <a href="qvalidator.html#State-enum">Invalid</a>.</li> <li>For a spin box that accepts lengths, "11cm" and "1in" are <a href="qvalidator.html#State-enum">Acceptable</a>, "11" and the empty string are <a href="qvalidator.html#State-enum">Intermediate</a>, and "http://example.com" and "hour" 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. 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> & <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 "-", 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> & <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> & <i>input</i>, <span class="type">int</span> & <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. the user types "4" 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> </div> </div> <div class="ft"> <span></span> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2013 Digia Plc 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> Digia, Qt and their respective logos are trademarks of Digia Plc 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> <script src="scripts/functions.js" type="text/javascript"></script> </body> </html>