QFileDialog文件对话框
Posted 五个板栗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)"
以上是关于QFileDialog文件对话框的主要内容,如果未能解决你的问题,请参考以下文章
QFileDialog::getSaveFileName() 在文件对话框中点击保存后返回一个空字符串