文件对话框
1.选择打开一个文件
文件对话框QFileDialog提供了一个用户选择文件或文件夹的对话框:
#include <QFileDialog>
//getOpenFileName()函数用来获取选择的文件名,参数:指定父窗口、设置标题、默认打开目录、文件类型过滤器。
QString fileName = QFileDialog::getOpenFileName(this, "File Dialog",
"/home/daowm/", "Picture(* png * jpg)");
qDebug()<<fileName;
运行程序显示:
可以设置多个不同类别的过滤器,不同类别间使用两个分号“;;”隔开,例如:
QString fileName = QFileDialog::getOpenFileName(this, "File Dialog", "/home/daowm/",
"Picture(* png * jpg);;TextFile(* txt)");
2.打开多个文件
可以使用getOpenFileNames()函数选择多个文件:
#include <QFileDialog>
QStringList fileNames = QFileDialog::getOpenFileNames(this, "File Dialog", "/home/daowm/",
"Picture(* png * jpg);;TextFile(* txt)");
qDebug()<<fileNames;
得到的fileNames为:
3.使用getSaveFileName()来实现保存文件对话框
4.使用ExistingDirectory()函数来获取一个已存在的文件夹路径
来源:oschina
链接:https://my.oschina.net/u/2368202/blog/719711