[Qt-interest] Writing a table proxy model for QFileSystemModel

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Tue Jun 29 18:27:09 CEST 2010


Hi All,

I'm trying to write a proxy model for a QFileSystemModel which will
proxy the data contained in a dir (set by calling setRootPath() on the
FS model) as a tabular data. The dimension of the table will be set
externally.

So eg if I have a dir A which has 3 subdirs and 7 files, if dir A is
set as the root and the table dimension is set to 3X3, i'll be showing
only the first 9 listings under dir A (the subdir data is not expanded
since table models are not hierarchical).

I have written a proxy model that can proxy a QStringListModel as a
table. I've applied a QTableView onto it and it has worked fine.

I feel writing a proxy for a FS model should be similar. Once I get
the root index from which the table data has to be proxied (model
index got by setRootPath()), proxying the data as a table should be
similar to what is needed for proxying a list model data.

BUT. I'm not able to use the model index that I get from a call to
setRootPath().

Eg:

$ $ ls -go /tmp/test/
total 8
-rw-r--r-- 1    0 2010-06-29 21:44 a.txt
-rw-r--r-- 1    0 2010-06-29 21:44 b.txt
-rw-r--r-- 1    0 2010-06-29 21:44 c.txt
drwxr-xr-x 2 4096 2010-06-29 21:44 d
drwxr-xr-x 2 4096 2010-06-29 21:45 e

<snip>
...
QFileSystemModel *model = new QFileSystemModel(this);
QModelIndex idx = model->setRootPath("/tmp/test/);

qDebug() << "rows=" << model->rowCount(idx);
qDebug() << "cols=" << model->columnCount(idx);
...
</snip>

returns:

rows= 0
cols= 4

Shouldn't it have returned "rows" as 5 (3 regular files + 2 dirs) ?
(I'm assuming here that the file system model stores the data in a
hierarchical manner, similar to the tree model shown in the examples).

Regards,
-mandeep



More information about the Qt-interest-old mailing list