PDA

View Full Version : Help with QDir model



allstar
15th December 2007, 15:19
Hi,
I am new in Qt and I i have a QTreeWidget and QTreeModel and I dont know how to get the selected filename when I click on the file in Tree Widget. Please send code If you can. (I really dont understand the model/view architecture.) Thanks a lot.

tree = new QTreeView(dockWidget);
QDirModel *model = new QDirModel(tree);
tree->setModel(model);

jpn
15th December 2007, 15:31
Well, you can connect to for example QAbstractItemView::activated(QModelIndex) or QAbstractItemView::clicked(QModelIndex) and use the index passed as parameter, or you can get the current index via QAbstractItemView::currentIndex().

Once you have the index at hand, you can do


QModelIndex index = ...
if (index.isValid())
{
QString filePath = dirModel->filePath(index);
// or
QFileInfo fileInfo = dirModel->fileInfo(index);
...
}