C++ 从QFileSystemModel中的文件路径和文件名获取QModelIndex
我需要从QFileSystemModel中的文件路径和文件名获取QModelIndex。我看到有一个索引函数,它接受一个文件路径,但我不知道列参数应该做什么。您必须覆盖QFileSystemModel的方法,以便可以从QML访问它:C++ 从QFileSystemModel中的文件路径和文件名获取QModelIndex,c++,qt,qml,qt5,qfilesystemmodel,C++,Qt,Qml,Qt5,Qfilesystemmodel,我需要从QFileSystemModel中的文件路径和文件名获取QModelIndex。我看到有一个索引函数,它接受一个文件路径,但我不知道列参数应该做什么。您必须覆盖QFileSystemModel的方法,以便可以从QML访问它: class DisplayFileSystemModel : public QFileSystemModel { Q_OBJECT public: ... Q_INVOKABLE QModelIndex index(const QString
class DisplayFileSystemModel : public QFileSystemModel {
Q_OBJECT
public:
...
Q_INVOKABLE QModelIndex index(const QString &path, int column = 0) const
{
return QFileSystemModel::index(path, column);
}
...
};
然后在QML中使用以下形式:
your_model.index(your_fullpath)