【发布时间】:2018-05-10 03:34:29
【问题描述】:
我需要从QFileSystemModel 中的文件路径和文件名中获取 QModelIndex。我看到有 index 函数接受 filepath 但我不知道列参数应该做什么。
【问题讨论】:
标签: c++ qt qml qt5 qfilesystemmodel
我需要从QFileSystemModel 中的文件路径和文件名中获取 QModelIndex。我看到有 index 函数接受 filepath 但我不知道列参数应该做什么。
【问题讨论】:
标签: c++ qt qml qt5 qfilesystemmodel
您必须覆盖 QFileSystemModel 的 index() 方法,以便可以从 QML 访问它:
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)
【讨论】: