如何在QTreeView中获取所选项目的路径?

时间:2014-12-18 09:50:12

标签: c++ qt qtreeview

我正在使用 QTreeView QFileSystem 模型:

QTreeView *treeview;
treeview = new QTreeView(win);
QFileSystemModel *fsm = new QFileSystemModel;   
fsm->setRootPath(QDir::currentPath()); 
treeview->setModel(fsm); 

......

我该如何实现?

1 个答案:

答案 0 :(得分:0)

QModelIndex index = treeview->currentIndex();
QString path;
if (index.isValid())
{
    path = fsm->filePath(index);
}