PDA

View Full Version : QDirModel and QListView > problem getting filepath



sadjoker
8th April 2008, 00:26
Hello guys. QT Newb here. Having a bad day...

First will show some code:


void ImCo::createDockWindows()
{
dock = new QDockWidget(tr("Available Frames"), this);
dock->setAllowedAreas(Qt::RightDockWidgetArea);

dirmodel = new QDirModel;
dirmodel->setFilter(QDir::Files | QDir::NoSymLinks);
dirmodel->setSorting(QDir::Name);
listView = new QListView();;
listView->setModel(dirmodel);
listView->setRootIndex(dirmodel->index(QDir::currentPath() + "/frames"));
dock->setWidget(listView);
connect(listView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(test(const QModelIndex &)));
addDockWidget(Qt::RightDockWidgetArea, dock);
opt->addAction(dock->toggleViewAction());
}

void ImCo::test(const QModelIndex &index){
int r = index.row();
// I click on one of the files showed on the QListView, and i need the path to the clicked file !!!
ww.some_func(path_to_the_file, var1, var2...);//this func needs the path to the file so it can be opened from other class
}

I`m forming a dock window which is showing the contents of a directory underneath my executable. When i click on a file on the dock QListView i want to call a function which has a parameter with a path to the file i clicked on the listView. So my question is: how to get the path to the file i clicked for the function ImCo::test. I only get the number of the item trough index.row. I don`t know how to get the filepath from the dirmodel. Hope i explained it well. Thanx in advance.

ChristianEhrlicher
8th April 2008, 06:44
I would say - read the docs (http://doc.trolltech.com/4.3/qdirmodel.html). There're enough functions where you can retrieve informations about the current file from the model index.

sadjoker
8th April 2008, 10:35
Wow, how can i miss those... starting now on fresh mind and it seems so easy lol
I think i needed a rest the last night.
Thank you :)