PDA

View Full Version : QFileSystemModel and QDirModel



lvlike
3rd December 2010, 22:19
Hello,

i wanted to use a model to select a folder in a treeview and then get directories and files within this folder.
i picked QDirModel and saw the following remark :


The usage of QDirModel is not recommended anymore. The QFileSystemModel class is a more performant alternative.
so i decided to use QFileSystemModel :
- i waited a few seconds each time i launched the program for the explorer to be displayed
- i tried to retrieve the number of rows at a given index but since the expanding process is asynchronous, it was difficult to retrieve the result.
- i tried then to list the children of a given index with a QDir object, but i couldn't set the same sort order for QFileSystemModel and QDir. For example, QFileSystemModel sorts numbered files like this : 3, 10, 2000 ... and QDir sorts the same files like this : 10, 2000, 3.

Since i needed the same sort order for my program, i finally gave up QFileSystemModel and tried the deprecated QDirModel.

And then i was surprised to see that :
- i didn't have to wait for the explorer to be displayed
- the expanding process was synchronous and the rowCount result was the expected one
- i could set the same flags for the sort order (QDir::SortFlags), or use only the QDirModel to get the children (synchronous process).

So my questions are the following ones :

Did i misunderstand the usage of QFileSystemModel in one or more of the three cases given above ?

If I did not, could it be possible to take into account these previous remarks to improve the QFileSystemModel or to make another class in case we would need the old QDirModel functionalities ?

Thanks for reading, and sorry if i made any language mistake (English is not my native language).

simon_kong
1st November 2011, 03:11
Waiting for the answer....