Qt logo

QFileDialog Class Reference


The QFileDialog provides a dialog widget for inputting file names. More...

#include <qfiledialog.h>

Inherits QDialog.

List of all member functions.

Public Members

Public Slots

Signals

Static Public Members

Protected Members


Detailed Description

The QFileDialog provides a dialog widget for inputting file names.

Example:

    QString fileName = QFileDialog::getOpenFileName();
    if ( !fileName.isNull() ) {                 // got a file name
        ...
    }

There are two ready-made convenience functions, getOpenFileName() and getSaveFileName(), which may be used like this:

    QString s( QFileDialog::getOpenFileName() );
    if ( s.isNull() )
        return;

    open( s ); // open() being your function to read the file

See also: QPrintDialog.

Examples: qdir/qdir.cpp movies/main.cpp


Member Type Documentation

QFileDialog::Mode

This enum type is used to set and read QFileDialog's operating mode. The defined values are:

Examples: qdir/qdir.cpp


Member Function Documentation

QFileDialog::QFileDialog ( QWidget * parent=0, const char * name=0, bool modal=FALSE )

Constructs a file dialog with a parent, name and modal flag.

The dialog becomes modal if modal is TRUE, otherwise modeless.

QFileDialog::QFileDialog ( const QString & dirName, const QString & filter = QString::null, QWidget * parent=0, const char * name=0, bool modal=FALSE )

Constructs a file dialog with a parent, name and modal flag.

The dialog becomes modal if modal is TRUE, otherwise modeless.

QFileDialog::~QFileDialog ()

Destroys the file dialog.

void QFileDialog::addWidgets ( QLabel * l, QWidget * w, QPushButton * b ) [protected]

Adds 1-3 widgets to the bottom of the file dialog. l is the (optional) label, which is put beneath the "file name" and "file type" labels, w is a (optional) widget, which is put beneath the file type combo box, and b is the (you guessed it - optional) button, which is put beneath the cancel button.

If you don't want to add something in one of the columns, pass 0.

It is not currently possible to add more than one row.

const QDir * QFileDialog::dir () const

Returns the active directory in the file dialog.

See also: setDir().

void QFileDialog::dirEntered ( const QString & ) [signal]

This signal is emitted when the user has selected a new directory.

QString QFileDialog::dirPath () const

Returns the active directory path string in the file dialog.

See also: dir() and setDir().

bool QFileDialog::eventFilter ( QObject * o, QEvent * e ) [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QObject.

void QFileDialog::fileHighlighted ( const QString & ) [signal]

This signal is emitted when the user highlights a file.

void QFileDialog::fileSelected ( const QString & ) [signal]

This signal is emitted when the user selects a file.

QString QFileDialog::getExistingDirectory ( const QString & dir = QString::null, QWidget * parent = 0, const char * name = 0 ) [static]

Ask the user for the name of an existing directory, starting at dir. Returns the name of the directory the user selected.

If dir is null, getExistingDirectory() starts wherever the previous file dialog left off.

QString QFileDialog::getOpenFileName ( const QString & startWith = QString::null, const QString & filter= QString::null, QWidget * parent = 0, const char * name = 0 ) [static]

Opens a modal file dialog and returns the name of the file to be opened.

If startWith is the name of a directory, the dialog starts off in that directory. If startWith is the name of an existing file, the dialogs starts in that directory, and with startWith selected.

Only files matching filter are selectable. If filter is QString::null, all files are selectable.

If widget and/or name is provided, the dialog will be centered over widget and named name.

getOpenFileName() returns a null string if the user cancelled the dialog.

This static function is less capable than the full QFileDialog object, but is convenient and easy to use.

Example:

    // start at the current working directory and with *.cpp as filter
    QString f = QFileDialog::getOpenFileName( QString::null, "*.cpp", this );
    if ( !f.isEmpty() ) {
        // the user selected a valid existing file
    } else {
        // the user cancelled the dialog
    }

getSaveFileName() is another convenience function, equal to this one except that it allows the user to specify the name of a nonexistent file name.

See also: getSaveFileName().

QStringList QFileDialog::getOpenFileNames ( const QString & filter= QString::null, const QString & dir = QString::null, QWidget * parent = 0, const char * name = 0 ) [static]

Lets the user select N files from a single directory, and returns a list of the selected files. The list may be empty, and the file names are fully qualified (i.e. "/usr/games/quake" or "c:\\quake\\quake").

filter is the default glob pattern (which the user can change). The default is all files. dir is the starting directory. If dir is not supplied, QFileDialog picks something presumably useful (such as the directory where the user selected something last, or the current working directory).

parent is a widget over which the dialog should be positioned and name is the object name of the temporary QFileDialog object.

Example:

    QStringList s( QFileDialog::getOpenFileNames() );
    // do something with the files in s.

QString QFileDialog::getSaveFileName ( const QString & startWith = QString::null, const QString & filter= QString::null, QWidget * parent = 0, const char * name = 0 ) [static]

Opens a modal file dialog and returns the name of the file to be saved.

If startWith is the name of a directory, the dialog starts off in that directory. If startWith is the name of an existing file, the dialogs starts in that directory, and with startWith selected.

Only files matching filter are selectable. If filter is QString::null, all files are selectable.

If widget and/or name is provided, the dialog will be centered over widget and named name.

Returns a null string if the user cancelled the dialog.

This static function is less capable than the full QFileDialog object, but is convenient and easy to use.

Example:

    // start at the current working directory and with *.cpp as filter
    QString f = QFileDialog::getSaveFileName( QString::null, "*.cpp", this );
    if ( !f.isEmpty() ) {
        // the user gave a file name
    } else {
        // the user cancelled the dialog
    }

getOpenFileName() is another convenience function, equal to this one except that it does not allow the user to specify the name of a nonexistent file name.

See also: getOpenFileName().

QFileIconProvider * QFileDialog::iconProvider () [static]

Returns the icon provider currently in use. By default there is no icon provider and this function returns 0.

See also: setIconProvider() and QFileIconProvider.

void QFileDialog::keyPressEvent ( QKeyEvent * ke ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

QFileDialog::Mode QFileDialog::mode() const

Returns the file mode of this dialog.

See also: setMode().

void QFileDialog::rereadDir ()

Re-reads the active directory in the file dialog.

It is seldom necessary to call this function. It is provided in case the directory contents change and you want to refresh the directory list box.

void QFileDialog::resizeEvent ( QResizeEvent * ) [virtual protected]

Handles resize events for the file dialog.

Reimplemented from QWidget.

QString QFileDialog::selectedFile () const

Returns the selected file name.

If a file name was selected, the returned string contains the absolute path name. The returned string is a null string if no file name was selected.

See also: QString::isNull().

Examples: qdir/qdir.cpp

void QFileDialog::setDir ( const QDir & dir )

Sets a directory path for the file dialog.

See also: dir().

void QFileDialog::setDir ( const QString & pathstr ) [slot]

Sets a directory path string for the file dialog.

See also: dir().

void QFileDialog::setFilter ( const QString & newFilter ) [slot]

Sets the filter spec in use to newFilter.

If newFilter matches the regular expression ([a-zA-Z0-9\.\*\?]*)$ (ie. it ends with a normal wildcard expression enclosed in parentheses), only the parenthesized is used. This means that these two calls are equivalent:

     fd->setFilter( "All perl files (*.pl)" );
     fd->setFilter( "*.pl" )

void QFileDialog::setFilters ( const char ** types ) [slot]

Sets this file dialog to offer types in the File Type combo box. types must be a null-terminated list of strings; each string must be in the format described in the documentation for setFilter().

See also: setFilter().

void QFileDialog::setFilters ( const QStringList & ) [slot]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void QFileDialog::setIconProvider ( QFileIconProvider * provider ) [static]

Sets all file dialogs to use provider to select icons to draw for each file. By default there is no icon provider, and QFileDialog simply draws a "folder" icon next to each directory and nothing next to the files.

See also: QFileIconProvider and iconProvider().

void QFileDialog::setMode ( Mode newMode )

Sets this file dialog to newMode, which can be one of Directory (directories are accepted), ExistingFile (existing files are accepted), AnyFile (any valid file name is accepted) or ExistingFiles (like ExistingFile, but multple files may be selected)

See also: mode().

Examples: qdir/qdir.cpp

void QFileDialog::setSelection ( const QString & filename )

Sets the default selection to filename. If filename is absolute, setDir() is also called.

Examples: qdir/qdir.cpp


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright İ 1999 Troll TechTrademarks
Qt version 2.0.2