Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Absolute path of files and folders in QSortFilterProxyModel+QTreeview
Forum Update on Monday, May 27th 2025

Absolute path of files and folders in QSortFilterProxyModel+QTreeview

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.6qsortfilterproxqtreeviewabsolutepath
2 Posts 1 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PunitP Offline
    PunitP Offline
    Punit
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • PunitP Offline
      PunitP Offline
      Punit
      wrote on last edited by
      #2

      Problem Solved.

      CODE

      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.
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved