Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView, QFileSystemModel, QSortFilterProxyModel -> Invalid Filename when try to rename directory

QTreeView, QFileSystemModel, QSortFilterProxyModel -> Invalid Filename when try to rename directory

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    km22
    wrote on last edited by km22
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are the old and new names ? Do you have the permissions to modify the files your testing on ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        km22
        wrote on last edited by km22
        #3

        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.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          km22
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Lucky.Juan
              wrote on last edited by
              #6

              Hi, does your problem be solved? I found the same problem, confused me for a several days.

              1 Reply Last reply
              0
              • JackkkkkJ Offline
                JackkkkkJ Offline
                Jackkkkk
                wrote on last edited by
                #7

                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.

                JonBJ 1 Reply Last reply
                0
                • JackkkkkJ Jackkkkk

                  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.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @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 with QFileSystemModel's creation of a QFileSystemWatcher 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.

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved