Absolute path of files and folders in QSortFilterProxyModel+QTreeview
Solved
General and Desktop
-
I am using QSortFilterProxyModel in QTreeView for filtering and showing specific folder. Its working fine. but my problem is when i click on any of the item of QTreeView. I am not able to get its information like absolute path. Can anyone please tell me how to get full/absolute path of selected item in QTreeview?.
CODE:
mainview=new TreeView(this); connect(mainview,SIGNAL(clicked(const QModelIndex &)),this,SLOT(showFilesDetails(const QModelIndex &))); void MainWindow::showFilesDetails(const QModelIndex &index) { QString selectedrow=fullPath(index); ----- } QString MainWindow::fullPath(const QModelIndex &index) { QString path('/'); QModelIndex parent = index; while (parent.isValid()) { path.prepend('/' + parent.data().toString()); parent = parent.parent(); } return path; }
I have selected a folder "test2" in my Qtreeview and the location of this folder is ""/Users/macwaves/Desktop/test2"" but using this helping function [fullPath], I am getting ""/Desktop/test2/"" as a result. I found this solution after searching many forums but It's not working.
Please help me.