I have a drive labeled as "Local Data" mounted at "/media/Local Data". And my program directory is also in "/media/Local Data/Programming". I would like to set "Local Data" to be the root path of a QFileSystemModel. I cannot find a way to do it.
Here is my code:
QFileSystemModel* model = new QFileSystemModel;
model->setRootPath("/media/Local Data");
QTreeView tree;
tree.setRootIndex(model->index("/media/Local Data");
tree.setModel(model);
qDebug() << QDir::currentPath();
// "/media/Local Data/Files/Programming/C++/build-FileSystemModel-Desktop_Qt_5_5_1_GCC_64bit-Debug"
tree.setMinimumSize(900,500);
tree.show();
I get the error QAbstractItemView::setRootIndex failed : index must be from the currently set model
.
When I run the program, it always give me the root "/" as the root path.
How can I achieve this?