当前位置:网站首页>QFileDialog select multiple files or folders
QFileDialog select multiple files or folders
2022-04-23 08:19:00 【Ott_ Glodon】
Qt Provides QFileDialog Used to select files or folders , The usage is as follows :
#include <QDebug>
#include <QFileDialog>
// Select one or more files
void Dialog::on_pushBtn_Files_clicked()
{
// Quickly select a file
//QString sFileName = QFileDialog::getOpenFileName(this," Select File ","/","C++ files(*.cpp);;C files(*.c);;Head files(*.h)");
//qDebug() << " File name :" << sFileName;
QFileDialog *fileDialog = new QFileDialog(this);
fileDialog->setFileMode(QFileDialog::Directory);
// Set the title of the window
fileDialog->setWindowTitle(" Please select a file ");
// You can also use the following code to set multiple filters
QStringList filters;
filters << "Image files (*.png *.xpm *.jpg)"
<< "Text files (*.txt)"
<< "Any files (*)";
fileDialog->setNameFilters(filters); // This function name is followed by one more s, Indicates setting multiple filters . See clearly .
//QFileDialog::ExistingFiles Multiple files , It can also be used to select folders QFileDialog::Directory.
fileDialog->setFileMode(QFileDialog::ExistingFiles);
// If you want to save the file , Then you need to set it again
//fileDialog.setAcceptMode(QFileDialog::AcceptSave);
// Pop-up dialog box
if (fileDialog->exec() == QDialog::Accepted)
{
QStringList listFiles = fileDialog->selectedFiles();
for (auto fileName : listFiles)
{
qDebug() << " File name :" << fileName;
}
}
}
// Select the folder
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() << " Folder name :" << selectDir.at(0);
}
}
版权声明
本文为[Ott_ Glodon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230714487371.html
边栏推荐
- Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
- LeetCode简单题之三除数
- 有意思的js 代码
- LeetCoed18. Sum of four numbers
- Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
- Thinkphp6 + JWT realizes login verification
- 如何在SQL Server中导入excel数据,2019版
- ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建
- ASAN 极简原理
- Install MySQL for Ubuntu and query the average score
猜你喜欢
Qt利用QtXlsx操作excel文件
Install MySQL for Ubuntu and query the average score
Talk about the basic but not simple stock data
Online yaml to XML tool
Kubernetes in browser and IDE | interactive learning platform killercoda
总线结构概述
LeetCode简单题之三除数
[untitled]
CSV column extract column extraction
WordPress爱导航主题 1.1.3 简约大气网站导航源码网址导航源码
随机推荐
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
Canvas learning Chapter 1
一篇文章看懂变量提升(hoisting)
Search the complete navigation program source code
LeetCode15. Sum of three
An idea plug-in that doesn't work, but can install X
5.6 综合案例-RTU-
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
redis主从服务器问题
dried food! Point based: differentiable Poisson solver
Interesting JS code
QFileDialog 选择多个文件或文件夹
Smart business card applet business card details page function implementation key code
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
How to import Excel data in SQL server, 2019 Edition
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
AAAI 2022 recruit speakers!!
微信小程序 catchtap=“toDetail“ 事件问题
There are some problems when using numeric type to query string type fields in MySQL
MySQL数据库中delete、truncate、drop原理详解