Qt学习笔记,获取给定目录下面的所有文件名,及其path
QDirModel listmodel;
QString rootpath = "/home/powerlinux/";
QDir dir(rootpath);
//QStringList dirs = dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs);
QStringList dirs = dir.entryList();
for(int i=0; i<dirs.size(); i++){
QModelIndex index = listmodel.index(rootpath+dirs.at(i));
QString filepath = listmodel.filePath(index);
qDebug() <<dirs.at(i)<< "'s index file path" << filepath;
}
本文介绍如何使用Qt中的QDirModel和QDir类来获取指定目录下的所有文件名及路径。通过示例代码展示了如何初始化QDir并利用entryList方法获取文件列表,最后遍历这些文件并打印出它们的路径。
1017

被折叠的 条评论
为什么被折叠?



