0

I'm developing a Qt application on Windows. To show the files of a specific folder, I'm using QTreeView together with QFileSystemModel. So far so good, but I came across a very specific issue which is driving me nuts: while I'm with a folder expanded in my application, I can't do anything with its parent folder.

I built a small project only to show this issue. Here's how I define my QFileSystemModel and apply it to my QTreeView:

QFileSystemModel *myModel = new QFileSystemModel;
myModel->setRootPath(myRootPath);
ui->treeView->setModel(myModel);

To exemplify my problem, check out this image

While I have "Test Folder 2" not expanded, I can do what I want to "Test Folder". I can rename, move, or even delete via Windows Explorer, and everything is applied to my program. However, when I expand "Test Folder 2", suddenly my "Test Folder" is not editable anymore. Windows says the folder is "open in another application".

I believe anyone can reproduce this issue with the three lines above, so I don't think it's a project specific problem. Does anyone knows why this is happening?

EDIT: Apparently this is a windows only problem. Just tried on linux and it worked just fine. Is this a NTFS problem? Any ideas?

1 Answers1

0

You should try to set the read only property.

#include <QApplication>
#include <QTreeView>
#include <QFileSystemModel>

int main(int argc, char** args) {
    QApplication app(argc, args);
    auto myModel = new QFileSystemModel;
    myModel->setReadOnly(true);
    auto treeView = new QTreeView;
    myModel->setRootPath("C:/Temp/A");
    treeView->setModel(myModel);
    treeView->show();
    app.exec();
}
Aleph0
  • 5,816
  • 4
  • 29
  • 80
  • @PericlesCarvalho: That is strange. I tried it with `setReadOnly(false)` and I was not able to edit folder. Then I changed to `setReadOnly(true)` and it worked. – Aleph0 Jun 17 '19 at 17:53
  • @PericlesCarvalho: Just tried it again under Ubuntu and it is still the same desired behavior. – Aleph0 Jun 17 '19 at 17:57
  • That is indeed strange, because I'm on Linux Mint (ext4 file system), and it does work even when I don't use setReadOnly. On windows (NTFS file system) it doesn't work either way. Which Qt Version are you using? – Pericles Carvalho Jun 17 '19 at 18:08
  • @PericlesCarvalho: `qtdiag` says that I'm using Qt 5.9.5 at home! At work it was 5.10.0 and it was also working on Windows 7. – Aleph0 Jun 17 '19 at 18:19