简体   繁体   English

在 listWidget 中显示文件夹和子文件夹中的所有文件

[英]display all Files in Folder and Subfolder in listWidget

I want to display all *.dat files which are in a selected path including the subfolder: my selected folder is "C:\iba\dat" and in iba there are two other folders Energie and Prozess and in these two folders are my Files which I want to display in my ListWidget.我想显示选定路径中的所有 *.dat 文件,包括子文件夹:我选择的文件夹是“C:\iba\dat”,在 iba 中还有另外两个文件夹 Energie 和 Prozess,在这两个文件夹中是我的文件我想在我的 ListWidget 中显示。

FAeingabe::FAeingabe(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FAeingabe)
{
    ui->setupUi(this);
    //icon
    setWindowIcon(QIcon(":/Icons/icon.ico"));

    QDir myPath("C:\\iba\\dat");
    QStringList nameFilters;
    nameFilters<<"*.dat";
    myPath.setFilter(QDir::AllEntries | QDir::Files | QDir::NoDotAndDotDot | QDir::NoDot);
    faList = myPath.entryList();
    ui->listWidget->addItems(faList);
    ui->total->setText(QString("%1").arg(ui->listWidget->count()));
}

I get this:我明白了:
在此处输入图像描述

First, you have not used your nameFilters.首先,你没有使用你的 nameFilters。 Second, you should use QDirIterator for getting the list of files.其次,您应该使用 QDirIterator 来获取文件列表。

QDirIterator it(QStringLiteral("C:\\iba\\dat"), QStringList() << "*.dat", QDir::Files, QDirIterator::Subdirectories);
QStringList faList;
while (it.hasNext())
       faList.append(it.next());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM