当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
396. Rotate Function
How to read books and papers
Generate and parse tokens using JWT
The simple problem of leetcode is to calculate the numerical sum of strings
dmp引擎工作总结(2021,光剑)
An idea plug-in that doesn't work, but can install X
Detailed explanation of ansible automatic operation and maintenance (I) installation and deployment, parameter use, list management, configuration file parameters and user level ansible operating envi
396. Rotate Function
Distributed service governance Nacos
freertos学习02-队列 stream buffer message buffer
An article understands variable lifting
PHP high precision computing
php生成短链接:将数字转成字母,将字母转成数字
How to import Excel data in SQL server, 2019 Edition
Rearranging log files for leetcode simple question
Discussion on ES6 tail tune optimization
【学习】从零开始的音视频开发(9)——NuPlayer
C语言学习记录——삼십팔 字符串函数使用和剖析(2)
Data security has become a hidden danger. Let's see how vivo can make "user data" armor again
华硕笔记本电脑重装系统后不能读取usb,不能上网