0

I need to get the QModelIndex from a filepath and filename in a QFileSystemModel. I saw there is the index function which takes a filepath but I don't know what the column argument should do.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
maxwell
  • 357
  • 4
  • 14

1 Answers1

1

You have to overwrite the index() method of QFileSystemModel so that it can be accessed from QML:

class DisplayFileSystemModel : public QFileSystemModel {
    Q_OBJECT
public:
    ...
    Q_INVOKABLE QModelIndex index(const QString &path, int column = 0) const
    {
        return QFileSystemModel::index(path, column);    
    }
    ...
};

And then in QML you use it following form:

your_model.index(your_fullpath)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241