I show a QFileSystemModel through a QTreeView.
Whenever the user clicks on a directory (expanded or not expanded) I want to get a list of the files inside this directory.
void MyModel::selectionChanged(const QItemSelection& selected,const QItemSelection& deselected) {
for (auto const & it : selected.indexes()) {
for (int i=0;i<rowCount(it);i++) {
auto child = it.child(i, it.column());
qDebug() << fileName(child);
}
}
}
The problem with the above code is that this only seems to work once that particular directory has been expanded. As long as the directory has never been expanded (since program start) rowCount is 0.
How can I force the model to populate the children of the given model index? Without necessarily showing the children in the view? One level of children indexes would be enough in this case.