Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QString QFileDialog::getExistingDirectory ( QWidget parent = 0,
const QString caption = QString(),
const QString dir = QString(),
Options  options = ShowDirsOnly 
) [static]

This is a convenience static function that will return an existing directory selected by the user.

doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12

This function creates a modal file dialog with the given parent widget. If the parent is not 0, the dialog will be shown centered over the parent widget.

The dialog's working directory is set to dir, and the caption is set to caption. Either of these may be an empty string in which case the current directory and a default caption will be used respectively. The options argument holds various options about how to run the dialog, see the QFileDialog::Option enum for more information on the flags you can pass.

Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog. On Mac OS X, the dir argument is ignored, the native dialog always displays the last visited directory. On Windows CE, if the device has no native file dialog, a QFileDialog will be used.

Under Unix/X11, the normal behavior of the file dialog is to resolve and follow symlinks. For example, if {/usr/tmp} is a symlink to {/var/tmp}, the file dialog will change to {/var/tmp} after entering {/usr/tmp}. If options includes DontResolveSymlinks, the file dialog will treat symlinks as regular directories.

Note that on Windows the dialog will spin a blocking modal event loop that will not dispatch any QTimers, and if parent is not 0 then it will position the dialog just under the parent's title bar.

See also:
getOpenFileName(), getOpenFileNames(), getSaveFileName()

Definition at line 1571 of file qfiledialog.cpp.

References QDialog::exec(), QList< T >::first(), QList< T >::isEmpty(), QString::isEmpty(), QString::normalized(), QDialog::result(), QString::right(), selectedFiles(), and QList< T >::value().

Referenced by FindFileDialog::browse(), and Window::browse().

{
    if (qt_filedialog_existing_directory_hook)
        return qt_filedialog_existing_directory_hook(parent, caption, dir, options);
    QFileDialogArgs args;
    args.parent = parent;
    args.caption = caption;
    args.directory = QFileDialogPrivate::workingDirectory(dir);
    args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
    args.options = options;

#if defined(Q_WS_WIN)
    if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog) && (options & ShowDirsOnly)
#if defined(Q_OS_WINCE)
        && qt_priv_ptr_valid
#endif
        ) {
        return qt_win_get_existing_directory(args);
    }
#elif defined(Q_WS_MAC)
    if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog)) {
        if (dir.isEmpty())
            args.directory = dir;
        QStringList files = qt_mac_get_open_file_names(args, 0, 0);
        if (!files.isEmpty())
            return files.first().normalized(QString::NormalizationForm_C);
        return QString();
    }
#endif

    // create a qt dialog
    QFileDialog dialog(args);
    if (dialog.exec() == QDialog::Accepted) {
        QString result = dialog.selectedFiles().value(0);
        if (!result.isEmpty() && result.right(1) != QLatin1String("/"))
            result += QLatin1Char('/');
        return result;
    }
    return QString();
}


Generated by  Doxygen 1.6.0   Back to index