[Qt-interest] QDirModel v. QFileSystemModel ?
Girish Ramakrishnan
girish at forwardbias.in
Sat Jun 13 07:24:14 CEST 2009
Stephen Collyer wrote:
> Could someone explain the relative merits/demerits of these two models ?
> The docs don't make it clear to me when one should be preferred over the
> other (apart from the separate thread thing with QFileSystemModel).
>
QFileSystemModel is like the successor to QDirModel. Main advantage is
that it populates the model in a thread unlike QDirModel which does it
in the UI thread. As a consequence, one cannot arbitrarily query
information in a QFileSystemModel because the data may not be available
yet (unlike a QDirModel which will perform the operation synchronously).
In practice, this is not a problem when displaying the model in a view.
> I need to be able to:
>
> a) display the contents of a particular directory in a treeview or listview
> b) select some subset of the displayed files
> c) retrieve the selected list in the form of filenames
>
> I don't need to create/modify directories or files. Given that fairly simple
> requirement, is there an obvious choice between the two ?
>
I would go with QFileSystemModel. iirc, Qt's own file dialog uses it, so
it's probably better tested :-)
> Also, why is there no equivalent of QFileSystemModel::setRootPath(..) ?
> Does QDirModel always provide access to the whole file system ?
Right. If you want to just display portion of the file system using
QDirModel, one can use the view's setRootIndex.
Girish
More information about the Qt-interest-old
mailing list