从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
Get QModelIndex from filepath and filename in QFileSystemModel
我需要从QFileSystemModel
中的文件路径和文件名中获取QModelIndex。我看到有一个index
函数需要filepath
但我不知道列参数应该做什么。
你必须覆盖 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)
相关文章:
- 从 Makefile 中的 $@ 获取文件名
- 有没有一种简单的方法可以从 c++ 中的路径获取文件名?
- C++获取当前文件名并在 WinExec 上使用它
- 从 SetClipboardData 挂钩获取文件名
- 从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
- 获取打开文件名 - 预选上次打开不起作用
- 获取模块文件名 Win 7/Win 10 上的不同行为
- 如何通过键入文件名来获取文件的目录。(C++)
- 获取 Qt 标签图像的文件名
- LLVM 如何获取调用站点文件名和行号
- 如何在C++中获取可执行文件名
- C++ ( MS V S ) 获取打开文件名
- 运行正则表达式时未选中的异常 - 从文件路径获取不带扩展名的文件名
- 获取打开文件名在默认目录打开'Computer'可能吗?
- 是否有一种便携式/标准的方法可以在堆栈跟踪中获取文件名和亚麻布
- 如何从文件夹中获取文件名,并将它们添加到QT中的孩子中
- 从 Windows 上的 tmpfile() 获取文件名
- 如何在c++中从shell中获取作为输入重定向的文件名
- 如何在选项卡视图中获取活动选项卡的文件名
- 如何获取函数调用的文件名和行号