I need to select all files from a QTableView, which has for model a QFileSystemModel.
The problem is that my QTableView displays the files and folders, so i need to select only the files.

This following Qt function selects the files and folders : it's why I cannot use it directly.
Qt Code:
  1. tableView->selectAll();
To copy to clipboard, switch view to plain text mode 

I have written a function which parse all elements from a QTableView and selects only the files.
Qt Code:
  1. //I get the modelIndex root
  2. QModelIndex rootIndex = tableView->rootIndex();
  3. //If the model is not valid, i cancel
  4. if(false == rootIndex.isValid())
  5. return;
  6. //I parse all lines from my root directory
  7. for(int i = 0 ; i < fileSystemModel->rowCount(rootIndex) ; i++)
  8. {
  9. //I get the current line
  10. QModelIndex currentIndex = fileSystemModel->index(i, 0, rootIndex);
  11. //If the current modelIndex is valid, i continue
  12. if(true == currentIndex.isValid())
  13. //If the current modelIndex is not a directory
  14. if(false == fileSystemModel->fileInfo(currentIndex).isDir())
  15. //If the current modelIndex is not already selected
  16. if(false == tableView->selectionModel()->isSelected(currentIndex))
  17. //I select it
  18. tableView->setCurrentIndex(currentIndex);
  19. }
To copy to clipboard, switch view to plain text mode 

This code seems ok. But, when i select a lot of files (for example 600), this function is very very slow...
It's much more slow than tableView->selectAll().

Have you got a solution to :
- optimize my function?
- or a easier way to select all files?

I thank you in advance!