From the Qt documentation:

QFileSystemModel will not fetch any files or directories until setRootPath() is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows. Unlike QDirModel(obsolete), QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls to rowCount() will return 0 until the model populates a directory. QFileSystemModel keeps a cache with file information. The cache is automatically kept up to date using the QFileSystemWatcher.

I'm using QTreeView together with a sub-classed QFileSystemModel which uses checkable boxes.
If I call QFileSystemModel::rowCount(index) before an item has been expanded in the tree I will receive '0', regardless of whether there are any subdirectories or files. However, once it has been expanded the correct row count will then be given when called again.

I think if you call QFileSystemModel::setRootPath() this will fetch the data from the specified file path, but it seems that it does not 'execute fast enough' (the cache is not updated) before I call QFileSystemModel::rowCount in my code below.

Qt Code:
  1. // Whenever a checkbox in the TreeView is clicked
  2. bool MyModel::setData(const QModelIndex& index, const QVariant& value, int role)
  3. {
  4. if (role == Qt::CheckStateRole)
  5. {
  6. if (value == Qt::Checked)
  7. {
  8. setRootPath(this->filePath(index));
  9. checklist.insert(index);
  10. set_children(index);
  11. }
  12. else
  13. {
  14. checklist.remove(index);
  15. unchecklist->insert(index);
  16. }
  17. emit dataChanged(index, index);
  18. return true;
  19. }
  20.  
  21. return QFileSystemModel::setData(index, value, role);
  22. }
  23.  
  24. // Counts how many items/children the node has (i.e. file/folders)
  25. void MyModel::set_children(const QModelIndex& index)
  26. {
  27. int row = this->rowCount(index);
  28.  
  29. qDebug() << QString::number(row);
  30.  
  31. }
To copy to clipboard, switch view to plain text mode 

Is there a way I can pre-emptively gather the sub-folder information before I try to count how many items are contained in that folder?

Thanks