access a file in the root path directory using QFileSystem hierarchy

  • Hi,
    I'm currently using the QFileSystemModel class and i just can't get the point of the row and column hierarchy. I got that the rows number defines the number of children. But what about the columns? What does it represent? I'm currently trying to set a new root path to the n°x child of a directory using its index but i just can't find this file using the row and column hierarchy that i naturally think of in the index(int row, int column, QModelIndex *parent) method which for me should be index(x,0 or 1 depending on 0-based or not, current root path file's index).

    I already thank you for your help.


  • I haven't used QFileSystemHierarchy, and I don't fully understand what your issues are, so I could be out on this... :)

    I think it has columns as well as rows partly because it's derived from QAbstractItemModel. I imagine the columns are a file's attributes (name, size, date, ...)(?) I think you should ignore columns. QModelIndex is the key thing.

    • Just use functions like QString filePath(const QModelIndex &index) const to get values from an item at an index
    • and functions like QModelIndex index(const QString &path, int column = 0) const and QModelIndex setRootPath(const QString &newPath) to generate an index from a path. Note that these do not need a column, only a path.


    I'm currently trying to set a new root path to the n°x child of a directory

    Use children() (from base class, QAbstractItemModel) to access and iterate a directory's child files/directories. Nothing to do with row/column.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.