Help with QFileSystemModel
How can QFileSystemModel be used to create a QStringList of full pathnames of directories?
This is what I'm trying to do:
Code:
{
int rowCount = fileSystemModel->rowCount(parent);
int columnCount = fileSystemModel->columnCount(parent);
for (int i=0; i<rowCount; i++)
{
for (int j=0; j<columnCount; j++)
{
QFileInfo fileInfo
= fileSystemModel
->fileInfo
(mi
);
if (!paths.contains(fileInfo.absoluteFilePath()))
{
paths << fileInfo.absoluteFilePath();
}
bool hasChildren = fileSystemModel->hasChildren(mi);
if (hasChildren)
{
paths << getDirectoryTree(fileInfo.absoluteFilePath());
}
}
}
return paths;
}
If you set the root path on fileSystemModel, then call getDirectoryTree() above, it works fine for the first directory level. However, when it recursively calls getDirectoryTree() using the child nodes, the rowCount is always 0.
Obviously I'm just not understanding the concept behind QAbstractItemModel in order to iterate through all values. In my case there is a root directory with about 100 subdirectories, most of which have several subdirectories, etc. (over 3,500 total).
All I want to do is get all the paths of the directories in a QFileSystemModel.
Re: Help with QFileSystemModel
QFileSystemModel can return zero for rowCount until the node is populated, as it uses a seperate thread for populating the tree. It'll send a signal when the count has changed.
I'm not really sure how to get it to what you want, and it's not really meant for that.
Maybe QDir would be better for you, as that isn't threaded, and you can call entryInfoList to get a list of all files and directories in the directory.
Re: Help with QFileSystemModel
Maybe that's the problem. I've already implemented the feature a few different ways, using QDirModel, QDir, and QDirIterator. The issue is with performance. There are almost 4,000 directories and it takes 3-4 seconds to perform the operation. I was just hoping for a faster solution.
Re: Help with QFileSystemModel
What is the intended last result? As in, what are you going to do with your list of filenames once you have them?
There might be better way.
Re: Help with QFileSystemModel
The intended use is to find all directories below a starting directory that contain a certain string. That list will be presented at various places within the application and the search string may be different.