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
Was it helpful?

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:

  1. In QtAssistant, go to Qt Reference Documentation->Overviews->View Classes and you have your example.

  2. 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 )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top