Is there an easy way to make some QStringList of files displaying in QTreeView as a tree? Of course we can split every path by "/" and do some stuff like appendRow in QStandardItemModel and take a result. But I think there must be a simplier way. For example, we have list of files like this (QStringList):
"dir/subdir/file.dat",
"dir/app.exe",
"other_dir/file2.dat"
Result must be a QTreeView like this:
Is there an easy way to make some QStringList of files displaying in QTreeView as a tree?
if the data is implied to be QStringList
than the suggestion is to convert it to TreeItem-based data and use Qt documentation example "Simple Tree Model Example". You cannot avoid creating tree-like structure one way or another for that. Find that example with Qt Creator or in its directory and look for TreeModel class definition/implementation.
If the data is not from QStringList or some other form of in-memory collection but from actual file system: of course it is very doable. All you need is QFileSystemModel and QTreeView. One of possible somewhat similar examples here.
Create the minimum UI you need and use the model filter like that:
auto* dirModel = new QFileSystemModel(this);
dirModel->setFilter(QDir::NoDotAndDotDot |
QDir::Files | QDir::Dirs);
... or you may specify better filter yourself if needed.