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. QFileSystemWatcher - file renaming, what is your new name?
Forum Updated to NodeBB v4.3 + New Features

QFileSystemWatcher - file renaming, what is your new name?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 2.7k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    ChanchoCiego
    wrote on last edited by
    #1

    hello,

    QFileSystemWatcher can tell me that a file was renamed, but how do I know which is your new name?

    thank you very much,

    regards,

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

      Hi,

      The signal provides all the information you need:

      @void QFileSystemModel::fileRenamed(const QString & path, const QString & oldName, const QString & newName)@

      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
      • R Offline
        R Offline
        Rondog
        wrote on last edited by
        #3

        QFileSystemWatcher won't tell you that kind of information.

        You can store a list of known files or directory contents and guess as to what changed by comparing the updated list to the last known contents. I wouldn't rely on this though as there are many reasons why directory contents may change.

        The proper way to do this would be to use the internal system file name and attach to this. In GNU/Linux you would use something like 'inotify' to do this which would respond back when any change occurred (including renaming or moving a file).

        I know OS X can do this as well. My favorite text editor can immediately recognize when a file is renamed or even moved to the trash (it follows it) so I know the capability is there.

        I don't know what Windows can do. I have never seen any Windows application that can track a file when it is renamed or moved. It may not be able to do this.

        When you rename a watched file QFileSystemWatcher will remove the file from the watched list so I don't think it monitors anything other then the file name (?).

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChanchoCiego
          wrote on last edited by
          #4

          Thank you very much SGaist,

          I notice that QFileSystemModel uses QFileSystemWatcher for homework, this can take a lot of resources because I use QFileSystemWatcher to monitor changes and deletions and QFileSystemModel for renames? would not redundant?

          I say this thinking that for each file to be monitored must create an instance of QFileSystemModel to monitor renames, if the monitor files are in different directories, this what I can not control because the user is going to be the one to decide how many files will be open

          Thank you very much,

          regards,

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

            First thing, sorry, I misread the title.

            I wouldn't create a QFileSystemModel per file, that wouldn't do any good. However it might be a good alternative to watch a folder in your case

            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
            • F Offline
              F Offline
              freeDNA
              wrote on last edited by
              #6

              In Windows, ReadDirectoryChangesW() can watch for folder content changes:

              The names of the dirs / files that have been created / deleted / modified.
              Both the old and new names of the dir / file in the case of renaming.

              1 Reply Last reply
              0

              • Login

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