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

Doc unclear for the QFileSystemWatcher

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.14.0 Alpha
    • 5.4.2, 5.5.0 Beta
    • Documentation
    • None
    • 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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: