0

I'm using Qt5. The code is really simple and goes like this:

struct DirEdit {
    QLineEdit *lineedit;
    QToolButton *button;
    QListView *view;
    QString dirPath;
    QFileSystemModel dirModel;
    bool ready {false};
};

Then in the source file:

for (std::size_t i = 0; i != c_lanes; ++i) {
    dirEdits[i].view->setModel(&dirEdits[i].dirModel);
    dirEdits[i].dirModel.setFilter(QDir::Files);
    dirEdits[i].dirModel.setProperty(fIdProp, (uint)i);
}

and then finally when the user chooses a path to display the contents of in a QListView:

DirEdit& de = dirEdits[folderId];
de.dirPath = selectedDirPath;
de.lineedit->setText(selectedDirPath);
de.dirModel.setRootPath(selectedDirPath);
de.view->setRootIndex(de.dirModel.setRootPath(selectedDirPath));

Now when I select /home/srsly (the home folder, this being on a Fedora 25 Linux system), the current folder, where the program is being ran from, gets appended to the beginning of the list. The filters are set to exclude directories as you can see. What can be the reason for this strange behavior?

iksemyonov
  • 4,106
  • 1
  • 22
  • 42
  • Unsure why on Fedora the filter is applied like that. I would consider the default filter: QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs comparing to yours which overrides all this OR flags. What if you try to filter with QDir::NoDotAndDotDot | QDir::Files? – Alexander V Jan 25 '17 at 19:17
  • Yep, tried the above combo as well, gave me the same result. What is really curious is how the folder changes according to the working directory. However, this only happens in the home directory. When the working directory is outside ~, the effect is gone. – iksemyonov Jan 25 '17 at 19:22
  • Maybe doing more routing directory filtering will help you: http://stackoverflow.com/questions/250890/using-qsortfilterproxymodel-with-a-tree-model – Alexander V Jan 25 '17 at 20:23

0 Answers0