How to use a QTreeView Model to display a list of files/folders get through mtp stack

2.4k Views Asked by At

I'm currently building an application which need to access to a device through the MTP stack.

I'm developping the code in c++ and Qt to easily be able to port the code on different platform.

I have based the Ui on TreeView to display the folder and ListView to display the list of files of the selected folder.

Most of example are using :

model->setRootPath("F:/Qt/GUI/files"); 
treeView->setModel(model); 
treeView->setRootIndex(model->index("F:/Qt/GUI/files"));

All these models are based on model which accessing to the local HD but in my case, I need to do it through list of folders/files using MTP Api. The backend is working, I mean accessing to the device is ok but I'm still thinkin on how to display the tree of folder and create a model.

Thanks

1

There are 1 best solutions below

0
On

Please, refer to the Qt Model/View tutorial and Model/View programming.

In general you shall create new model and in the bare minimum override a couple of pure virtual functions. Since it's a Tree structure, you should subclass QAbstractItemModel.