The easiest way to create a QFileDialog is to use the static functions.
By default, a platform-native file dialog will be used if the platform has one. In that case, the widgets which would otherwise be used to construct the dialog will not be instantiated, so related accessors such as layout() and itemDelegate() will return null. You can set the DontUseNativeDialog option to ensure that the widget-based implementation will be used instead of the native dialog.
See also QDir, QFileInfo, QFile, QColorDialog, QFontDialog, Standard Dialogs Example, and Application Example.
QFileDialog::Directory 2 The name of a directory. Both files and directories are displayed. However, the native Windows file dialog does not support displaying files in the directory chooser.
QFileDialog::DontUseNativeDialog 0x00000010 Don't use the native file dialog. By default, the native file dialog is used unless you use a subclass of QFileDialog that contains the Q_OBJECT macro, or the platform does not have a native dialog of the type that you require.
QFileDialog::DontUseCustomDirectoryIcons 0x00000080 Always use the default directory icon. Some platforms allow the user to set a different icon. Custom icon lookup cause a big performance impact over network or removable drives. Setting this will enable the QFileIconProvider::DontUseCustomDirectoryIcons option in the icon provider. This enum value was added in Qt 5.2.
This property holds the URL schemes that the file dialog should allow navigating to.
Setting this property allows to restrict the type of URLs the user will be able to select. It is a way for the application to declare the protocols it will support to fetch the file content. An empty list means that no restriction is applied (the default). Supported for local files ("file" scheme) is implicit and always enabled; it is not necessary to include it in the restriction.
When the current file changes for local operations, this signal is emitted with the new file name as the path parameter.
When the current file changes, this signal is emitted with the new file URL as the url parameter.
This signal is emitted for local operations when the user enters a directory.
Returns the url of the directory currently being displayed in the dialog.
When the selection changes for local operations and the dialog is accepted, this signal is emitted with the (possibly empty) selected file.
When the selection changes for local operations and the dialog is accepted, this signal is emitted with the (possibly empty) list of selected files.
On Windows and macOS, this static function will use the native file dialog and not a QFileDialog. However, the native Windows file dialog does not support displaying files in the directory chooser. You need to pass DontUseNativeDialog to display files using a QFileDialog.
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 below the parent's title bar.
Warning: Do not delete parent during the execution of the dialog. If you want to do this, you should create the dialog yourself using one of the QFileDialog constructors.
This is a convenience static function that will return an existing directory selected by the user. If the user presses Cancel, it returns an empty url.
The function is used similarly to QFileDialog::getExistingDirectory(). In particular parent, caption, dir and options are used in the exact same way.
The main difference with QFileDialog::getExistingDirectory() comes from the ability offered to the user to select a remote directory. That's why the return type and the type of dir is QUrl.
The supportedSchemes argument allows to restrict the type of URLs the user will be able to select. It is a way for the application to declare the protocols it will support to fetch the file content. An empty list means that no restriction is applied (the default). Supported for local files ("file" scheme) is implicit and always enabled; it is not necessary to include it in the restriction.
When possible, this static function will use the native file dialog and not a QFileDialog. On platforms which don't support selecting remote files, Qt will allow to select only local files.
See also getExistingDirectory(), getOpenFileUrl(), getOpenFileUrls(), and getSaveFileUrl().
On Windows, and macOS, this static function will use the native file dialog and not a QFileDialog.
This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns an empty url.
The function is used similarly to QFileDialog::getOpenFileName(). In particular parent, caption, dir, filter, selectedFilter and options are used in the exact same way.
The main difference with QFileDialog::getOpenFileName() comes from the ability offered to the user to select a remote file. That's why the return type and the type of dir is QUrl.
See also getOpenFileName(), getOpenFileUrls(), getSaveFileUrl(), and getExistingDirectoryUrl().
This is a convenience static function that will return one or more existing files selected by the user. If the user presses Cancel, it returns an empty list.
The function is used similarly to QFileDialog::getOpenFileNames(). In particular parent, caption, dir, filter, selectedFilter and options are used in the exact same way.
The main difference with QFileDialog::getOpenFileNames() comes from the ability offered to the user to select remote files. That's why the return type and the type of dir are respectively QList<QUrl> and QUrl.
See also getOpenFileNames(), getOpenFileUrl(), getSaveFileUrl(), and getExistingDirectoryUrl().
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 below the parent's title bar. On macOS, with its native file dialog, the filter argument is ignored.
This is a convenience static function that returns a file selected by the user. The file does not have to exist. If the user presses Cancel, it returns an empty url.
The function is used similarly to QFileDialog::getSaveFileName(). In particular parent, caption, dir, filter, selectedFilter and options are used in the exact same way.
The main difference with QFileDialog::getSaveFileName() comes from the ability offered to the user to select a remote file. That's why the return type and the type of dir is QUrl.
The supportedSchemes argument allows to restrict the type of URLs the user will be able to select. It is a way for the application to declare the protocols it will support to save the file content. An empty list means that no restriction is applied (the default). Supported for local files ("file" scheme) is implicit and always enabled; it is not necessary to include it in the restriction.
See also getSaveFileName(), getOpenFileUrl(), getOpenFileUrls(), and getExistingDirectoryUrl().
Returns the MIME type filters that are in operation on this file dialog.
Sets the current MIME type filter.
Selects the given url in the file dialog.
Note: The non-native QFileDialog supports only local files.
Returns The mimetype of the file that the user selected in the file dialog.
Returns a list of urls containing the selected files in the dialog. If no files are selected, or the mode is not ExistingFiles or ExistingFile, selectedUrls() contains the current path in the viewport.
See also selectedNameFilter() and selectUrl().
Note: On iOS, if you set directory to QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last(), a native image picker dialog will be used for accessing the user's photo album. The filename returned can be loaded using QFile and related APIs. For this to be enabled, the Info.plist assigned to QMAKE_INFO_PLIST in the project file must contain the key NSPhotoLibraryUsageDescription. See Info.plist documentation from Apple for more information regarding this key. This feature was added in Qt 5.5.
Sets the file dialog's current directory url.
Note: On Windows, it is possible to pass URLs representing one of the virtual folders, such as "Computer" or "Network". This is done by passing a QUrl using the scheme clsid followed by the CLSID value with the curly braces removed. For example the URL clsid:374DE290-123F-4565-9164-39C4925E467B denotes the download location. For a complete list of possible values, see the MSDN documentation on KNOWNFOLDERID. This feature was added in Qt 5.5.
See also directoryUrl() and QUuid.
Sets the filters used in the file dialog, from a list of MIME types.
Convenience method for setNameFilters(). Uses QMimeType to create a name filter from the glob patterns and description defined in each MIME type.
Use application/octet-stream for the "All files (*)" filter, since that is the base MIME type for all files.
Calling setMimeTypeFilters overrides any previously set name filters, and changes the return value of nameFilters().
<< "image/png"  // will show "PNG image (*.png)"
<< "application/octet-stream"; // will show "All files (*)"
See also setMimeTypeFilters() and setNameFilters().
Note that the filter *.* is not portable, because the historical assumption that the file extension determines the file type is not consistent on every operating system. It is possible to have a file with no dot in its name (for example, Makefile). In a native Windows file dialog, *.* will match such files, while in other types of file dialogs it may not. So it is better to use * if you mean to select any file.
setMimeTypeFilters() has the advantage of providing all possible name filters for each file type. For example, JPEG images have three possible extensions; if your application can open such files, selecting the image/jpeg mime type as a filter will allow you to open all of them.
When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) selected url.
See also currentUrlChanged() and QDialog::Accepted.
When the selection changes and the dialog is accepted, this signal is emitted with the (possibly empty) list of selected urls.