Browse folders and add their files to a list with qt
-
25-09-2019 - |
Question
Hello Great community of SO!
I have created a GUI application with qt and I added a QTreeWidget and a 2 buttons (add and delete) in my main window.
Is it possible to find examples of code in order to learn how to add and delete files to this QTreeWidget ?
- I would like to display their size, name and location into the list
Solution
For directory browsing try QDir. To create and remove files use QFile. Quite a lot of examples and tutorials can be found here Qt documentation. Just select your release.
OTHER TIPS
Did you look at the demos that come bundled with Qt itself? I can tell you of two examples:
In QtAssistant, go to Qt Reference Documentation->Overviews->View Classes and you have your example.
More elaborate: In QtAssistant, go to: Qt Reference Documentation->Tutorials and Examples: Under XQuery,XPath you have File System Example.
Adding file can be as simple as opening a new file (taking the filename from user) and closing it (I don't know what exactly you want here - some equivalent of "touch" command?).
For deleting, you can call: bool QDir::remove ( const QString & fileName )