Important: Please read the Qt Code of Conduct -

Absolute path of files and folders in QSortFilterProxyModel+QTreeview

  • 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?.


    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 = 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.

  • Problem Solved.


    QModelIndex index2=proxymodel->mapToSource(index); 
    //Returns the source model index (In my case it was QFileSystemModel)
    QString selectedrow=filemodel->fileInfo(index2).absoluteFilePath();
    //filemodel is My QFileSystem Model.