| |||
| Classes - Annotated - Tree - Functions - Home - Structure | |||
The QInputDialog class provides a simple convenience dialog to get a single value from the user. More...
#include <qinputdialog.h>
Inherits QDialog.
The QInputDialog is a simple dialog which can be used if you need to get a single input value from the user. The input value can be a string, a number or an item from a list. A label has to be set to tell the user what they should input.
In this Qt version the 4 static convenience functions, getText(), getInteger(), getDouble() and getItem() are available.
Use it like this:
bool ok = FALSE;
QString text = QInputDialog::getText(
tr( "Application name" ),
tr( "Please enter your name" ),
QLineEdit::Normal, QString::null, &ok, this );
if ( ok && !text.isEmpty() )
;// user entered something and pressed ok
else
;// user entered nothing or pressed cancel
There are more static convenience methods!
See also getText(), getInteger(), getDouble() and getItem().
If ok is not-null it will be set to TRUE if the user pressed OK and FALSE if the user pressed Cancel. The dialog's parent is parent; the dialog is called name. The dialog will be modal.
This method returns the floating point number which has been entered by the user.
Use this static method like this:
bool ok = FALSE;
double res = QInputDialog::getDouble(
tr( "Application name" ),
tr( "Please enter a decimal number" ),
33.7, 0, 1000, 2, &ok, this );
if ( ok )
;// user entered something and pressed ok
else
;// user pressed cancel
If ok is not-null it will be set to TRUE if the user pressed OK and FALSE if the user pressed Cancel. The dialog's parent is parent; the dialog is called name. The dialog will be modal.
This method returns the number which has been entered by the user.
Use this static method like this:
bool ok = FALSE;
int res = QInputDialog::getInteger(
tr( "Application name" ),
tr( "Please enter a number" ), 22, 0, 1000, 2, &ok, this );
if ( ok )
;// user entered something and pressed ok
else
;// user pressed cancel
If ok is not-null it will be set to TRUE if the user pressed OK and FALSE if the user pressed Cancel. The dialog's parent is parent; the dialog is called name. The dialog will be modal.
This method returns the text of the current item, or if editable is TRUE, the current text of the combobox.
Use this static method like this:
QStringList lst;
lst << "First" << "Second" << "Third" << "Fourth" << "Fifth";
bool ok = FALSE;
QString res = QInputDialog::getItem(
tr( "Application name" ),
tr( "Please select an item" ), lst, 1, TRUE, &ok, this );
if ( ok )
;// user selected an item and pressed ok
else
;// user pressed cancel
This method returns the text which has been entered in the line edit.
Use this static method like this:
bool ok = FALSE;
QString text = QInputDialog::getText(
tr( "Application name" ),
tr( "Please enter your name" ),
QLineEdit::Normal, QString::null, &ok, this );
if ( ok && !text.isEmpty() )
;// user entered something and pressed ok
else
;// user entered nothing or pressed cancel
Example: ftpclient/ftpmainwindow.cpp.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
| Copyright © 2000 Trolltech | Trademarks | Qt version main-beta1
|