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

QString QFileDialog::getSaveFileName ( QWidget parent = 0,
const QString caption = QString(),
const QString dir = QString(),
const QString filter = QString(),
QString selectedFilter = 0,
Options  options = 0 
) [static]

This is a convenience static function that will return a file name selected by the user. The file does not have to exist.

It 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.

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

The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected. Only files that match the filter are shown. The filter selected is set to selectedFilter. The parameters dir, selectedFilter, and filter may be empty strings. 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.

The default filter can be chosen by setting selectedFilter to the desired value.

The dialog's caption is set to caption. If caption is not specified then a default caption will be used.

Under Windows and Mac OS X, this static function will use the native file dialog and not a QFileDialog.

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. On Mac OS X, the filter argument is ignored.

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.

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

Definition at line 1491 of file qfiledialog.cpp.

References QDialog::exec(), QString::isEmpty(), QDialog::result(), selectedFiles(), selectNameFilter(), setAcceptMode(), and QList< T >::value().

Referenced by AddressBook::exportAsVCard(), MainWindow::saveAs(), MainWindow::saveFile(), Screenshot::saveScreenshot(), and AddressBook::saveToFile().

{
    if (qt_filedialog_save_filename_hook)
        return qt_filedialog_save_filename_hook(parent, caption, dir, filter, selectedFilter, options);
    QFileDialogArgs args;
    args.parent = parent;
    args.caption = caption;
    args.directory = QFileDialogPrivate::workingDirectory(dir);
    args.selection = QFileDialogPrivate::initialSelection(dir);
    args.filter = filter;
    args.mode = AnyFile;
    args.options = options;

#if defined(Q_WS_WIN)
    if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog)) {
        return qt_win_get_save_file_name(args, &(args.directory), selectedFilter);
    }
#elif defined(Q_WS_MAC)
    if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog)) {
        if (dir.isEmpty())
            args.directory = dir;
        QString result = qt_mac_get_save_file_name(args, &(args.directory), selectedFilter);
        return result.normalized(QString::NormalizationForm_C);
    }
#endif

    // create a qt dialog
    QFileDialog dialog(args);
    dialog.setAcceptMode(AcceptSave);
    if (selectedFilter)
        dialog.selectNameFilter(*selectedFilter);
    if (dialog.exec() == QDialog::Accepted) {
        if (selectedFilter)
            *selectedFilter = dialog.selectedFilter();
        return dialog.selectedFiles().value(0);
    }

    return QString();
}


Generated by  Doxygen 1.6.0   Back to index