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

Doc unclear for the QFileSystemWatcher



    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.14.0 Alpha
    • 5.4.2, 5.5.0 Beta
    • Documentation
    • None
    • da46ea92e537501c932343f65e11032a2f5984f3 (qt/qtbase/5.14)


      Based on issues :

      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
      => 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()) {


        Issue Links

          For Gerrit Dashboard: QTBUG-46483
          # Subject Branch Project Status CR V



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



                Gerrit Reviews

                  There are no open Gerrit changes