Extracting path of a file sleected from a listbox
Hi
I am trying to get the path of a selected file in a listbox.I am able to get the filename after selecting the file by the following code
QModelIndex index = ui->treeView->currentIndex();
ui->listWidget_2->addItem(index.data().toString());
I want to get the full path of the selected file also, if there is any way please guide me.
thanks
Re: Extracting path of a file sleected from a listbox
We have no idea what is in the model you have, how you populated it, or what non-full file name you have so we cannot possibly give you concrete direction.
Re: Extracting path of a file sleected from a listbox
Hi
I am sorry for so less information, I have used the following code
QFileSystemModel *model = new QFileSystemModel;
model->setRootPath("/home/");
ui->treeView->setModel(model);
ui->treeView->setRootIndex(model->index("/home/"));
So I have this file browser in my treeview and I am able to extract file names from this treeview to a listbox.
I also want to have full path of the selected file from the tree view.
Re: Extracting path of a file sleected from a listbox
Take a look at QFileInfo, you could use following
Re: Extracting path of a file sleected from a listbox
Can I use the FileInfo for the selected index.data() from the treeView, since its not a file?
Re: Extracting path of a file sleected from a listbox
Quote:
Can I use the FileInfo for the selected index.data() from the treeView, since its not a file?
Yes you can. QFileInfo can be used with the file name (QString()) which can be index.data().
Re: Extracting path of a file sleected from a listbox
Re: Extracting path of a file sleected from a listbox
QFileSystemModel::filePath()
This worked for me, thank u all for the help