当前位置:网站首页>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
边栏推荐
- The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi
- 巨头押注的全屋智能,正在驱动海信、华为、小米们「自我革命」
- 3C裝配中的機械臂運動規劃
- An article understands variable lifting
- Online yaml to XML tool
- Comparison of indoor positioning methods of several intelligent robots
- 智能名片小程序名片详情页功能实现关键代码
- 网赚APP资源下载类网站源码
- Flatten arrays
- 华硕笔记本电脑重装系统后不能读取usb,不能上网
猜你喜欢
简述CPU
[programming practice / embedded competition] learning record of embedded competition (II): picture streaming based on TCP
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
An article understands variable lifting
Anti shake and throttling
在MATLAB中快速画圆(给出圆心坐标和半径就能直接画的那种)
mysql查询字符串类型的字段使用数字类型查询时问题
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
Go语学习笔记 - 数组 | 从零开始Go语言
LeetCode中等题之旋转函数
随机推荐
[problem solving] vs2019 solves the problem that the EXE file generated by compilation cannot be opened
Discussion on ES6 tail tune optimization
[effective go Chinese translation] part I
Go语学习笔记 - 语言接口 | 从零开始Go语言
How to import Excel data in SQL server, 2019 Edition
C outputs a two-dimensional array with the following characteristics.
Anti shake and throttling
An article understands variable lifting
clang 如何产生汇编文件
Fibula dynamic programming
Why are there 1px problems? How?
3C装配中的机械臂运动规划
校园转转二手市场源码下载
redis主从服务器问题
Compiler des questions de principe - avec des réponses
Go语学习笔记 - Slice、Map | 从零开始Go语言
Ubuntu安装Mysql并查询平均成绩
[programming practice / embedded competition] learning record of embedded competition (I): establishment of TCP server and web interface
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
js将树形结构数据转为一维数组数据