[SOLVED] Problem with QSortFilterProxyModel when changing of drive



  • Hi,
    I have subclassed QFileSystemModel to display the root directory as explained in
    "http://stackoverflow.com/questions/6496776/qtreeview-show-only-parent-directory-rather-than-parent-and-all-its-siblings":http://stackoverflow.com/questions/6496776/qtreeview-show-only-parent-directory-rather-than-parent-and-all-its-siblings

    Everything works well unless in one case, when the new current directory is on another drive. I.e for instance, when I'm displaying the content of directory D:/toto/tata and I want to display now the content of C:/titi. In this case, I have C: that is displayed in my explorer instead of titi.

    But changing from D:/toto/tata to D:/tutu works well. And changing from D:/toto/tata to "Computer" then to C:/titi also works well.

    Tracing the function filterAcceptsRow(), in the bad case, gives surprising things. Sometimes it just tests de drives. Sometimes it tests also directories (by first testing the path c:/titi, then testing c:/).

    So, I am pretty sure to have an error with QModelIndex in the function that is supposed to manage the change of root directory. For the moment, the code of this function is:

    @ void FileExplorerView::setSelected(const std::string &p_filePath)
    {
    QModelIndex rootModelIndex = this->m_fileModel->index(p_filePath.c_str());
    QModelIndex parentIndex = this->m_fileModel->parent(rootModelIndex);

     this->m_filterFileList->setRootDir(this->m_fileModel->filePath(rootModelIndex));
     
     this->m_fileModel->setRootPath(this->m_fileModel->filePath(parentIndex));
     this->setRootIndex(this->m_filterFileList->mapFromSource(parentIndex));
     this->collapseAll();
    
     rootModelIndex = this->m_fileModel->index(p_filePath.c_str());
     this->setCurrentIndex(this->m_filterFileList->mapFromSource(rootModelIndex));
     this->expand(this->m_filterFileList->mapFromSource(rootModelIndex));
    }
    

    @

    Thanks for your help.



  • Hi,
    I have finally found the problem. In the post I used as "reference" they are creating a filter for a fixed directory. I have modified it, by addind the method SetRootDir, to be able to change of directory. But I have not seem that in the QT doc it is written that in this case I must call the method InvalidateFilter().


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.