我查了下QDir::AllEntries
List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System).希望有用.根据你fileModel名字,试试改成QDir::Files.不知道对不对.
使用QT Creator可以可视化地使用控件,实现,在dialog.cpp初始化时
QString Path = "E:/";
fileModel = new QFileSystemModel (this);
fileModel->setFilter(QDir::Files | QDir::NoDotAndDotDot); // (QDir::QDir::AllDirs | QDir::NoDotAndDotDot); 这时显示的只是文件夹
fileModel->setRootPath(Path);
ui->tree->setModel (fileModel); //treeView控件显示出的只是文件.
如不是所要答案,请见谅.且同求正解.共同学习