QFileDialog文件对话框

QFileDialog能遍历整个文件系统来选择一个或者多个文件或者目录

函数原型(F1或者Fn+F1查看帮助文档,有更详细的解释)
QString QFileDialog::getOpenFileName(QWidget *parent = nullptr,
const QString &caption = QString(),
const QString &dir = QString(),
const QString &filter = QString(),
QString *selectedFilter = nullptr,
QFileDialog::Options options = Options());
QStringList QFileDialog::getOpenFileNames(QWidget *parent = nullptr, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = nullptr, QFileDialog::Options options = Options());
QString QFileDialog::getSaveFileName(QWidget *parent = nullptr, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = nullptr, QFileDialog::Options options = Options());
//选择已经有的目录
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
void QFileDialog::setDirectory(const QString &directory);
//可选择远程网路文件
QUrl QFileDialog::getSaveFileUrl(QWidget *parent = nullptr,
const QString &caption = QString(),
const QUrl &dir = QUrl(),
const QString &filter = QString(),
QString *selectedFilter = nullptr,
QFileDialog::Options options = Options(),
const QStringList &supportedSchemes = QStringList());
#include <QFileDialog>
#include <QString>
QString path1 = QFileDialog::getOpenFileName(this, "open file","/", "TXT文本文件 (*.txt);;(*.*) ");
if (path1.isEmpty())
return;
QString path2=QFileDialog::getSaveFileName(this, "save file path", "../", "blk文本文件 (*.blk);; 所有文件 (*.*)");
if (path2.isEmpty())
return;

要想使用多个过滤器的,用两个分号隔开

"Images ( *.png . xpm .jpg)";; Text files (*.txt);; XML files (*.xml)"

发表评论

相关文章