Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-46483

Doc unclear for the QFileSystemWatcher

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.4.2, 5.5.0 Beta
    • Fix Version/s: 5.14.0 Alpha
    • Component/s: Documentation
    • Labels:
      None
    • Commits:
      da46ea92e537501c932343f65e11032a2f5984f3 (qt/qtbase/5.14)

      Description

      Based on issues :
      QTBUG-46431
      QTBUG-24898

      it appears that the QFileSystemWatcher's documentation may be improved.

      Step to reproduce :
      1/ create a watcher and add a file
      2 / edit the file in an editor (works when using gedit)
      3/ save the file
      => the signal fileChanged(QString) is emitted
      BUT
      => the file is no more watched and the signal won't be emitted if the file is modified again if the file is modified again.

      The reason is the following :
      1/ In most editors, "save" is implemented with "delete the file / recreate the file".
      2/ deleting the file causes the file to be removed from the watcher => it is no more monitored, even though the path is immediately recreated.

      This behaviour is perfectly logical, and is not a bug.
      But it is worth being mentioned in the documentation !!!

      I propose to add something like the following to the QFileSystemWatcher doumentation :

      Note : note that when "saving" a file, many editors actually delete the file, then recreate it. In that case, the QFileSystemWatcher will emit the fileChanged(QString) signal once. However, since the file is deleted, it will be removed from the monitored file list : future modification of the file won't be monitored anymore, since it is actually another file (though with the same path).
      Workarround : when the fileChanged(QString) is received, check if the file has been removed from the monitored file list. If it has been removed, but if the path still exists on drive, readd the path to the monitored file list :

          if(  ! watcher.files().contains(_fileName)  && QFileInfo( _fileName).exists()) {
              m_watcher.addPath(_fileName);
          }
      

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              • Assignee:
                srutledg Shawn Rutledge
                Reporter:
                deac Delphine Passinge
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes