QFileSystemModel: include files from subfolders (Qt 5.5.1)
-
What do you want to use it for ?
-
The goal here is to find text files in a given path and list them in a QListView. If the user clicks on a text file in this list, he should be able to rename it and on a double click to edit the text file. So far so good, i got this covered.
In some rare cases text files are sorted inside sub directories, one by one - means 20 text files are in 20 sub directories. It is kinda lame to click through all the subs so my idea was to add a button or check box to also include all text files in this given root path.
The first part was easy and fast for me to accomplish but the second part - including text files from sub directories and add them to the QListView / QFileSystemModel is still a mystery to me. I'm still a Qt beginner, any help is appreciated.
Thank you!
-
Then a model based on QAbstractListModel that you populate using QDirIterator might be the simple way to go.
-
This is not an option, i rather give up on this and show additional files in a log window or any other way. If the user browses through directories and clicks C: for example, the app will lock for seconds or minutes if no ssd is present.
Is it really that complicated to include sub directories in QFileSystemModel?
-
Just to be sure I understand you correctly, your additional folders should act like a QFileSystemModel with a QFileSystemModel ?
-
I sort of found a solution that works. On button click i change the listview model from QFileSystemModel to QStringListModel and call a function and use QDirIterator to add filenames to a QStringList. It needs additional code but if QFileSystemModel can't be set to a recursive directory mode, i don't have a lot of options, i guess.
Is there any better solution?
Thanks!
-
Like I wrote, QFileSystemModel is optimized to avoid filing up your memory with everything it can find on the hard drive.
Your use case really sounds like QDirIterator is a better choice to retrieve the information you want.
-
I don't need all the files from a hard drive, just the files in all the sub directories inside directory. For example on Windows: C:\text-files\2016*.txt and all the *.txt files from C:\text-files\2016\1*.txt C:\text-files\2016\2*.txt and so on. I don't need files from C:\Windows or C:\Programs or ...
Edit: Editor is removing \ before * so please imagine them there! ^^
-
That I understood. That's why I think that QDirIterator is a better tool to find what you want on your drive.