当前位置:网站首页>QFileDialog 选择多个文件或文件夹
QFileDialog 选择多个文件或文件夹
2022-04-23 07:15:00 【欧特_Glodon】
Qt提供了QFileDialog 用来选择文件或者文件夹,具体用法如下:
#include <QDebug>
#include <QFileDialog>
// 选择一个或多个文件
void Dialog::on_pushBtn_Files_clicked()
{
// 快速选择一个文件
//QString sFileName = QFileDialog::getOpenFileName(this,"选择文件","/","C++ files(*.cpp);;C files(*.c);;Head files(*.h)");
//qDebug() << "文件名称:" << sFileName;
QFileDialog *fileDialog = new QFileDialog(this);
fileDialog->setFileMode(QFileDialog::Directory);
//设置窗口的标题
fileDialog->setWindowTitle("请选择文件");
//也可以使用下面代码设置多个过滤器
QStringList filters;
filters << "Image files (*.png *.xpm *.jpg)"
<< "Text files (*.txt)"
<< "Any files (*)";
fileDialog->setNameFilters(filters); //这个函数名称后面多了一个s,表示设置多个过滤器。要看清楚。
//QFileDialog::ExistingFiles 多个文件,还可以用来选择文件夹QFileDialog::Directory。
fileDialog->setFileMode(QFileDialog::ExistingFiles);
//如果是要保存文件,那就需要再设置一下
//fileDialog.setAcceptMode(QFileDialog::AcceptSave);
//弹出对话框
if (fileDialog->exec() == QDialog::Accepted)
{
QStringList listFiles = fileDialog->selectedFiles();
for (auto fileName : listFiles)
{
qDebug() << "文件名称:" << fileName;
}
}
}
// 选择文件夹
void Dialog::on_pushBtn_Dir_clicked()
{
QFileDialog *fileDialog = new QFileDialog(this);
fileDialog->setFileMode(QFileDialog::Directory);
fileDialog->exec();
auto selectDir = fileDialog->selectedFiles();
if (selectDir.size()>0)
{
qDebug() << "文件夹名称:" << selectDir.at(0);
}
}
版权声明
本文为[欧特_Glodon]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_37251750/article/details/124297836
边栏推荐
- 如何在SQL Server中导入excel数据,2019版
- Jetson Xavier NX(3)Bazel Mediapipe 安装
- Canvas learning Chapter 1
- Anti shake and throttling
- C language learning record -- use and analysis of string function (2)
- Asynchronous learning
- 一个没啥L用,但可以装X的IDEA插件
- Move layout (Flex layout, viewport label)
- 1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
- Upload labs range practice
猜你喜欢

The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi

在线YAML转XML工具

Go语学习笔记 - 语言接口 | 从零开始Go语言

thinkphp6+jwt 实现登录验证
![[programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface](/img/f1/09de53509479a01098d3cf46bf48eb.jpg)
[programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface

使用 Ingress 实现金丝雀发布

CSV Column Extract列提取

分布式服务治理Nacos

搜一下导航完整程序源码

一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载
随机推荐
Go语学习笔记 - 结构体 | 从零开始Go语言
The third divisor of leetcode simple question
sql 使用过的查询语句
Hump naming object
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
PHP generates short links: convert numbers to letters and letters to numbers
情境领导者-第七章、解决绩效问题
使用 Ingress 实现金丝雀发布
高精度焊接机械臂定位
Ignis公链的NFT生态发展:Unicorn.art的捐赠开发之路
[Effective Go 中文翻译]函数篇
常用正则表达式
The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi
Face to face summary 2
利用Js实现一个千分位
How does feign integrate hystrix
thinkphp6+jwt 实现登录验证
NFT ecological development of Ignis public chain: unicorn Donation and development of Art
Transformer-XL: Attentive Language ModelsBeyond a Fixed-Length Context 论文总结
[go] common concurrency model [generic version]