QTreeView, QFileSystemModel, QSortFilterProxyModel -> Invalid Filename when try to rename directory
-
Hello !
When i try to rename a directory in QTreeView - by doubleclick - a Messagebox called "Invalid Filename" pops up. No fileRenamed SIGNAL emitted. (Filename is ok. There are no special characters in the name. ("Test" for example also doesn`t work))
This only happens when node has been expanded once. When node was not expanded, everything works as expected.
I use QTreeView, QFileSystemModel with a QSortFilterProxyModel.this is what QFileSystemModel `s setData() does:
if (newName.isEmpty() || QDir::toNativeSeparators(newName).contains(QDir::separator()) || !QDir(filePath(parent(idx))).rename(oldName, newName)) { #ifndef QT_NO_MESSAGEBOX QMessageBox::information(0, QFileSystemModel::tr("Invalid filename"), QFileSystemModel::tr("<b>The name \"%1\" can not be used.</b><p>Try using another name, with fewer characters or no punctuations marks.") .arg(newName), QMessageBox::Ok); #endif // QT_NO_MESSAGEBOX
QDir::rename returns false in my case.
Why does QDir::rename() return false if this node was expanded in QTreeView ???
Any idears?
-
Hi,
What are the old and new names ? Do you have the permissions to modify the files your testing on ?
-
Hello !
For example: oldname = "Test"; newname = "Test1";
These are directories ! I have full permission ! Local file system!
I`m on windows 7 Qt5.5.Could it be, that the permission of parents changing, when i expand a node in qtreeview?
If the node i want to change is collapsed, rename works.
But was it expanded ONLY ONE TIME, rename doesn`t work anymore.
That means, it also doesnt work when i collapse an expanded node and try to rename. -
For example. I have this structure in QTreeView
- Folder1 |- Folder11 |- Folder111
All nodes are expanded.
QFileSystemModel readOnly set to false
Local File System !
QTreeView is set to AllEditTriggers
Folders are empty, no files !Click on "Folder1" in QTreeView for rename.
-> For some reason it is not possible to rename "Folder1" ! ! ! -
Can you share a minimal sample code where you setup the tree view and model to try to reproduce this behaviour ?
-
Hi, does your problem be solved? I found the same problem, confused me for a several days.
-
Exactly the same problem!
Windows10, Maya Pyside2 (python 2.7 + qt 5.6.1).Once the folder is expanded, it is "locked" and model.setData(index, "New Name", Qt.EditRole) fails, although there is no file name conflict.
@Jackkkkk
There are other reports of this on this forum and elsewhere on the web. There are reports in the Qt bug system, but no resolution. I believe you will find it is a Windows (NTFS filing system)-only bug, and is a consequence of the way Windows deals with that filing system combined withQFileSystemModel
's creation of aQFileSystemWatcher
behind the scenes.I suggest you might like to read through https://forum.qt.io/topic/110667/qfilesystemmodel-qtreeview-rename-failed-after-expanded-tree-item, which I presume is the same as your issue. At the very end of the last post there I suggested a possible workaround, but don't know if anyone adopted it. It's not nice, but if the alternative is that rename directory will not work here that is your choice.