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?


  • Lifetime Qt Champion

    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" ! ! !


  • Lifetime Qt Champion

    Can you share a minimal sample code where you setup the tree view and model to try to reproduce this behaviour ?


Log in to reply
 

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