<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- /tmp/qt-4.2.1-harald-1161357942206/qt-x11-opensource-src-4.2.1/src/gui/dialogs/qinputdialog.cpp --> <head> <title>Qt 4.2: QInputDialog Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td> <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="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td> <td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QInputDialog Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1> <p>The QInputDialog class provides a simple convenience dialog to get a single value from the user. <a href="#details">More...</a></p> <pre> #include <QInputDialog></pre><p>Inherits <a href="qdialog.html">QDialog</a>.</p> <ul> <li><a href="qinputdialog-members.html">List of all members, including inherited members</a></li> <li><a href="qinputdialog-qt3.html">Qt 3 support members</a></li> </ul> <a name="static-public-members"></a> <h3>Static Public Members</h3> <ul> <li><div class="fn"/>double <b><a href="qinputdialog.html#getDouble">getDouble</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, double <i>value</i> = 0, double <i>minValue</i> = -2147483647, double <i>maxValue</i> = 2147483647, int <i>decimals</i> = 1, bool * <i>ok</i> = 0, Qt::WindowFlags <i>f</i> = 0 )</li> <li><div class="fn"/>int <b><a href="qinputdialog.html#getInteger">getInteger</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, int <i>value</i> = 0, int <i>minValue</i> = -2147483647, int <i>maxValue</i> = 2147483647, int <i>step</i> = 1, bool * <i>ok</i> = 0, Qt::WindowFlags <i>f</i> = 0 )</li> <li><div class="fn"/>QString <b><a href="qinputdialog.html#getItem">getItem</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, const QStringList & <i>list</i>, int <i>current</i> = 0, bool <i>editable</i> = true, bool * <i>ok</i> = 0, Qt::WindowFlags <i>f</i> = 0 )</li> <li><div class="fn"/>QString <b><a href="qinputdialog.html#getText">getText</a></b> ( QWidget * <i>parent</i>, const QString & <i>title</i>, const QString & <i>label</i>, QLineEdit::EchoMode <i>mode</i> = QLineEdit::Normal, const QString & <i>text</i> = QString(), bool * <i>ok</i> = 0, Qt::WindowFlags <i>f</i> = 0 )</li> </ul> <ul> <li><div class="fn"/>4 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li> <li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li><div class="fn"/>2 properties inherited from <a href="qdialog.html#properties">QDialog</a></li> <li><div class="fn"/>55 properties inherited from <a href="qwidget.html#properties">QWidget</a></li> <li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li> <li><div class="fn"/>5 public functions inherited from <a href="qdialog.html#public-functions">QDialog</a></li> <li><div class="fn"/>195 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li> <li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li> <li><div class="fn"/>12 public functions inherited from <a href="qpaintdevice.html#public-functions">QPaintDevice</a></li> <li><div class="fn"/>4 public slots inherited from <a href="qdialog.html#public-slots">QDialog</a></li> <li><div class="fn"/>19 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li> <li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li> <li><div class="fn"/>3 signals inherited from <a href="qdialog.html#signals">QDialog</a></li> <li><div class="fn"/>1 signal inherited from <a href="qwidget.html#signals">QWidget</a></li> <li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li> <li><div class="fn"/>38 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li> <li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li> <li><div class="fn"/>1 protected function inherited from <a href="qpaintdevice.html#protected-functions">QPaintDevice</a></li> <li><div class="fn"/>1 protected slot inherited from <a href="qwidget.html#protected-slots">QWidget</a></li> </ul> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QInputDialog class provides a simple convenience dialog to get a single value from the user.</p> <p>The input value can be a string, a number or an item from a list. A label must be set to tell the user what they should enter.</p> <p>Four static convenience functions are provided: <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getInteger">getInteger</a>(), <a href="qinputdialog.html#getDouble">getDouble</a>() and <a href="qinputdialog.html#getItem">getItem</a>(). All the functions can be used in a similar way, for example:</p> <pre> bool ok; QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"), tr("User name:"), QLineEdit::Normal, QDir::home().dirName(), &ok); if (ok && !text.isEmpty()) textLabel->setText(text);</pre> <p>The <tt>ok</tt> variable is set to true if the user clicks <b>OK</b>; otherwise it is set to false.</p> <p align="center"><img src="images/inputdialogs.png" alt="Input Dialogs" /></p><p>The <a href="dialogs-standarddialogs.html">Standard Dialogs</a> example shows how to use QInputDialog as well as other built-in Qt dialogs.</p> <p>See also <a href="qmessagebox.html">QMessageBox</a> and <a href="dialogs-standarddialogs.html">Standard Dialogs Example</a>.</p> <hr /> <h2>Member Function Documentation</h2> <h3 class="fn"><a name="getDouble"></a>double QInputDialog::getDouble ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, double <i>value</i> = 0, double <i>minValue</i> = -2147483647, double <i>maxValue</i> = 2147483647, int <i>decimals</i> = 1, bool * <i>ok</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>Static convenience function to get a floating point number from the user. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>value</i> is the default floating point number that the line edit will be set to. <i>minValue</i> and <i>maxValue</i> are the minimum and maximum values the user may choose, and <i>decimals</i> is the maximum number of decimal places the number may have.</p> <p>If <i>ok</i> is non-null, *<i>ok</i> will be set to true if the user pressed OK and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p> <p>This function returns the floating point number which has been entered by the user.</p> <p>Use this static function like this:</p> <pre> bool ok; double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"), tr("Amount:"), 37.56, -10000, 10000, 2, &ok); if (ok) doubleLabel->setText(QString("$%1").arg(d));</pre> <p>See also <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getInteger">getInteger</a>(), and <a href="qinputdialog.html#getItem">getItem</a>().</p> <h3 class="fn"><a name="getInteger"></a>int QInputDialog::getInteger ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, int <i>value</i> = 0, int <i>minValue</i> = -2147483647, int <i>maxValue</i> = 2147483647, int <i>step</i> = 1, bool * <i>ok</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>Static convenience function to get an integer input from the user. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>value</i> is the default integer which the spinbox will be set to. <i>minValue</i> and <i>maxValue</i> are the minimum and maximum values the user may choose, and <i>step</i> is the amount by which the values change as the user presses the arrow buttons to increment or decrement the value.</p> <p>If <i>ok</i> is non-null *<i>ok</i> will be set to true if the user pressed <b>OK</b> and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p> <p>This function returns the integer which has been entered by the user.</p> <p>Use this static function like this:</p> <pre> bool ok; int i = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"), tr("Percentage:"), 25, 0, 100, 1, &ok); if (ok) integerLabel->setText(tr("%1%").arg(i));</pre> <p>See also <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getDouble">getDouble</a>(), and <a href="qinputdialog.html#getItem">getItem</a>().</p> <h3 class="fn"><a name="getItem"></a><a href="qstring.html">QString</a> QInputDialog::getItem ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, const <a href="qstringlist.html">QStringList</a> & <i>list</i>, int <i>current</i> = 0, bool <i>editable</i> = true, bool * <i>ok</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>Static convenience function to let the user select an item from a string list. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>list</i> is the string list which is inserted into the combobox, and <i>current</i> is the number of the item which should be the current item. If <i>editable</i> is true the user can enter their own text; if <i>editable</i> is false the user may only select one of the existing items.</p> <p>If <i>ok</i> is non-null <i>*a</i> ok will be set to true if the user pressed OK and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p> <p>This function returns the text of the current item, or if <i>editable</i> is true, the current text of the combobox.</p> <p>Use this static function like this:</p> <pre> QStringList items; items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter"); bool ok; QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"), tr("Season:"), items, 0, false, &ok); if (ok && !item.isEmpty()) itemLabel->setText(item);</pre> <p>See also <a href="qinputdialog.html#getText">getText</a>(), <a href="qinputdialog.html#getInteger">getInteger</a>(), and <a href="qinputdialog.html#getDouble">getDouble</a>().</p> <h3 class="fn"><a name="getText"></a><a href="qstring.html">QString</a> QInputDialog::getText ( <a href="qwidget.html">QWidget</a> * <i>parent</i>, const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, <a href="qlineedit.html#EchoMode-enum">QLineEdit::EchoMode</a> <i>mode</i> = QLineEdit::Normal, const <a href="qstring.html">QString</a> & <i>text</i> = QString(), bool * <i>ok</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>Static convenience function to get a string from the user. <i>title</i> is the text which is displayed in the title bar of the dialog. <i>label</i> is the text which is shown to the user (it should say what should be entered). <i>text</i> is the default text which is placed in the line edit. The <i>mode</i> is the echo mode the line edit will use. If <i>ok</i> is non-null <i>*a</i> ok will be set to true if the user pressed <b>OK</b> and to false if the user pressed <b>Cancel</b>. The dialog's parent is <i>parent</i>. The dialog will be modal and uses the widget flags <i>f</i>.</p> <p>This function returns the text which has been entered in the line edit. It will not return an empty string.</p> <p>Use this static function like this:</p> <pre> bool ok; QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"), tr("User name:"), QLineEdit::Normal, QDir::home().dirName(), &ok); if (ok && !text.isEmpty()) textLabel->setText(text);</pre> <p>See also <a href="qinputdialog.html#getInteger">getInteger</a>(), <a href="qinputdialog.html#getDouble">getDouble</a>(), and <a href="qinputdialog.html#getItem">getItem</a>().</p> <hr /> <h2>Member Function Documentation</h2> <h3 class="fn"><a name="getDouble-2"></a>double QInputDialog::getDouble ( const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, double <i>value</i> = 0, double <i>minValue</i> = -2147483647, double <i>maxValue</i> = 2147483647, int <i>decimals</i> = 1, bool * <i>ok</i> = 0, <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0, const char * <i>name</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Call getDouble(<i>parent</i>, <i>title</i>, <i>label</i>, <i>value</i>, <i>minValue</i>, <i>maxValue</i>, <i>decimals</i>, <i>ok</i>, <i>f</i>).</p> <p>The <i>name</i> parameter is ignored.</p> <h3 class="fn"><a name="getInteger-2"></a>int QInputDialog::getInteger ( const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, int <i>value</i> = 0, int <i>minValue</i> = -2147483647, int <i>maxValue</i> = 2147483647, int <i>step</i> = 1, bool * <i>ok</i> = 0, <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0, const char * <i>name</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Call getInteger(<i>parent</i>, <i>title</i>, <i>label</i>, <i>value</i>, <i>minValue</i>, <i>maxValue</i>, <i>step</i>, <i>ok</i>, <i>f</i>) instead.</p> <p>The <i>name</i> parameter is ignored.</p> <h3 class="fn"><a name="getItem-2"></a><a href="qstring.html">QString</a> QInputDialog::getItem ( const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, const <a href="qstringlist.html">QStringList</a> & <i>list</i>, int <i>current</i> = 0, bool <i>editable</i> = true, bool * <i>ok</i> = 0, <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0, const char * <i>name</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Call getItem(<i>parent</i>, <i>title</i>, <i>label</i>, <i>list</i>, <i>current</i>, <i>editable</i>, <i>ok</i>, <i>f</i>) instead.</p> <p>The <i>name</i> parameter is ignored.</p> <h3 class="fn"><a name="getText-2"></a><a href="qstring.html">QString</a> QInputDialog::getText ( const <a href="qstring.html">QString</a> & <i>title</i>, const <a href="qstring.html">QString</a> & <i>label</i>, <a href="qlineedit.html#EchoMode-enum">QLineEdit::EchoMode</a> <i>echo</i> = QLineEdit::Normal, const <a href="qstring.html">QString</a> & <i>text</i> = QString(), bool * <i>ok</i> = 0, <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0, const char * <i>name</i> = 0, <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> <i>f</i> = 0 ) <tt> [static]</tt></h3> <p>This is an overloaded member function, provided for convenience.</p> <p>Call getText(<i>parent</i>, <i>title</i>, <i>label</i>, <i>echo</i>, <i>text</i>, <i>ok</i>, <i>f</i>) instead.</p> <p>The <i>name</i> parameter is ignored.</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="30%">Copyright © 2006 <a href="trolltech.html">Trolltech</a></td> <td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="30%" align="right"><div align="right">Qt 4.2.1</div></td> </tr></table></div></address></body> </html>