Important: Please read the Qt Code of Conduct -

[SOLVED] Problem with QSortFilterProxyModel when changing of drive

  • Hi,
    I have subclassed QFileSystemModel to display the root directory as explained in

    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);

     rootModelIndex = this->m_fileModel->index(p_filePath.c_str());


    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