简体   繁体   中英

Get QModelIndex from filepath and filename in QFileSystemModel

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM