View Full Version : QFileSystemModel and mounted disks

15th December 2009, 09:43
Hi guys, I need to visualize the file system tree of two mounted partitions/disks. The user select wihich partition to see and then I show a QListView with the related file system from the selected disk. The user can now turn back and choose another disk.

I'm using a QFileSystemModel and this is the code:

FileSystemBrowser::FileSystemBrowser(QWidget *parent)
: QWidget(parent),
m_ui(new Ui::FileSystemBrowser),
m_fs(new QFileSystemModel(this))

this->connect(m_ui->backButton, SIGNAL(clicked()), this, SIGNAL(closeRequest()));
this->connect(m_ui->fileBrowser, SIGNAL(clicked(QModelIndex)), this, SLOT(cd(QModelIndex)));

// Update the model.
m_fs->setFilter(QDir::AllDirs | QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot);

// Update the view.

When the user select a disk, the setRootPath method is invoked with the pathname of the disk root directory.

void FileSystemBrowser::setRootPath(const QString& path)
QString root_path = QDir(path).canonicalPath();

// Update the model.
QModelIndex root = m_fs->index(root_path);

// Update the view.

The problem is that for each disk, the visualization works only the first time! The second time no entry is shown...

For example:

1) Select disk1.
2) The disk1 file system is shown.
3) Exit from disk1.
4) Reselect disk1.
5) No entry shown!
6) Exit form disk1.
7) Select disk2.
8) The disk2 file system is shown.
9) Exit from disk2.
10) Reselect disk2.
11) No entry shown!

Any ideas?