Important: Please read the Qt Code of Conduct -

QFileSystemWatcher's signal "directoryChanged" not emitted

  • Hi,
    I have deleted (not shift+delete) a directory that contains files under Windows 10.
    In my app that tests the QFileSystemWatcher, I have seen that there is not any directoryChanged signal for that directory that is emitted.(the watcher watch a parent directory of this directory)
    Should I register a Qt Bug ?
    I use the QFileSystemWatcher in another app, a file synchronisation software that is fast finished....
    The first bug that I have registered is reported...

  • Hi stephane78,

    you say: "the watcher watch a parent directory of this directory".

    The docs ( do not mention that any subfolders are watched.
    So I think you need to add all subfolders recursively starting from your parent directory to get the directoryChanged signal for
    a subfolder.

  • @sneubert I know that, and all the paths are added recursively at the beginning of my app and are added too when copying a new directory into the the watcher watch this path but doesn't emit a directoryChange signal for this path(subdirectory) when deleting (not shift +del) under Windows 10....
    so I will perhaps put a new Qt BUG
    does someone know if we buy a subscription if the people of Qt will correct this two bugs (this one and the older)? because we need QFileSYstemWatcher for our app and I have signaled the other bug since march 2016 and it is reported since.

  • Lifetime Qt Champion


    What bug is it ?

  • @SGaist I have reported this bug :
    (and my older bug on QfileSystemWatcher is 52226)


  • Lifetime Qt Champion

    Like suggested in both report, please provide a minimal compilable example.

    For it has two purposes: see what code triggers the problem and allows to build the example on other platforms.

  • @SGaist I have now uploaded a minimal project to test and display directorychange and filechange but it is not complete because it does'nt add the paths to watcher when adding new path....
    we use Qt -LGPL in our little company and (at home for personal projects)
    if our company buy a commercial license for three months, will be the two bugs be corrected ?

  • @SGaist if this project is not sufficient I will perhaps provide the whole code but this code belongs to my company......
    Buying a commercial license will perhaps help us to solve the two bugs?

  • Lifetime Qt Champion

    Paying customer bug will have more weight however I don't know how fast it will make things. I'm not working for the Qt Company and can't comment on such matter.

  • Might be worth you looking directly at the source code, see if you can get it sorted yourself, and submit a patch.

    Did you try if other environments are affected too? Any linux distribution for example?

  • @VRonin I didn't try all the OS, but I can later, but under linux there isn't any difference between del and shift+del like under windows (because I tested that with del under win10 so when you put the folder in the trashcan, but did'nt test really with shift+del...I think with shift+del under win7 it is ok but not sure 100%
    I will do more test so....
    but I have already looked at the code of QFile SystemWatcher for one year because of the older bug and I don't really understand it....if I could understand it I would have made myself the correction.I will try again to look at the code of QFileSystemWatcher

  • @VRonin OK there is the same problem under linux debian 8 with kde.when you move to thrash a subdirectory watched the signal directorychanged is not emitted and when you delete it with shift+del the signal is emitted...I have just tested now
    under windows 7 I can only delete with shift+del it doesn't allow me to delete with del so there isn't any problem
    I didn't test under mac os

  • @VRonin I have looked quickly at the source code of QFileSystemWatcher....(Qt5.6.2)
    first I don't find the definition of init() and initPollerEngine() of the class QFileSystemWatcherPrivate (qfilesystemwatcher_p.h) that are called in the constructor of QFileSystemWatcher and in the method addPaths.
    second, I have seen that there is a thread that derivate from QThread for windows, QWindowsFileSystemWatcherEngineThread, and the method run is redefinited l332 in qfilesystemwatcher_win.cpp,so that I understand it but don't understand all the details in the method run...

  • @VRonin I have seen where it emits the signal directoryChanged when the directory is deleted l.388 and l.385 I see if(fakeRemove||!fileInfo.exists()) but I don't understand the other things well.....

  • @VRonin I have looked too at the win32 functions findfirstchangenotification (used l.160) and find nextchangenotification (used l.364)....I think I must use a debug version of Qt to debug that because perhaps there is no change notification on the handle when we use a simple del to delete a directory ie send it to trashcan(without shift) ?

  • @VRonin or perhaps the error l.367 is another error than ERROR_ACCESS_DENIED that should be considered too and the that fakeRemove should be put to true too (or another boolean )

  • @VRonin what are the other errors of FindNextChangeNotification?didn't find them in the win32 msdn documentation.
    And I don't really know how to do debug of Qt ? because it is in QtCore,so I suppose I must take the project and source of QtCore, but my test project use not only QtCore but QtGui and QtWidget too....

  • I'll take a quick look and see if I can spot something in the source, no promises though

  • @VRonin Thank you vronin, do you know how I can debug QtCore (or corelib or io) with my test project synchro as executable with QtCreator and mingw-w64(the compiler of suppose I must take the source (single,the .zip) but don't really know how to do project synchro uses core,gui and widget but I suppose I must open corelib or io as project in QtCreator

  • @VRonin do you know how to get the version 5.6.2 of qtbase from with git? (to build it in debug and try to debug corelib)

  • Just clone the repository and check out the 5.6 branch

  • @VRonin ok thanks vronin...

  • @VRonin it is done.but to debug qfilesystemwatcher should I open in QtCreator (QtCore) and build it debug and put breakpoints and attach to my app synchro ?

  • @VRonin I want to put a breakpoint l.364 of QFileSystemWatcher_win.cpp and watch error l365

  • @VRonin there is "attach to unstarted application" and "debug an external application" in Qtcreator\debug. is it possible to use one this option to debug QtCore (corelib) with my app synchro.exe ?

  • @VRonin when building corelib I have this error ..\corelib\global\qt_pch.h:50:21: fatal error: qglobal.h: No such file or directory
    #include <qglobal.h>
    qglobal.h is in the directory but I think I lacks an environment variable ?

  • @VRonin OK I think I have found : I have copied the directory include of the source single (.zip) of 5.6.2 in the direcorty qtbase and I have put in my environment variable INCLUDE the path of directory include and reboot my windows...I think it will be ok

  • I have put

    INCLUDEPATH +="../../include"
    INCLUDEPATH +="../../include/QtCore"

    int he but I have an error In file included from ..\corelib\animation\qabstractanimation.cpp:143:0:
    ..\corelib\animation\qabstractanimation_p.h:52:31: fatal error: private/qobject_p.h: No such file or directory
    #include <private/qobject_p.h>

  • It think I will build the whole Qtbase as usually and then open the and put the directory of lib QtCored.dll as build directory and try to debug with my exe (synchro.exe)

  • Lifetime Qt Champion

    You have to, qtbase, unlike the other modules, requires that you run configure before building it.

  • @SGaist even after done configure,if I want to debug qtcore (corelib) in Qtcreator,it needs to be build with Qtcreator and I can't build it with Qtcreator (mingw).so I can't debug corelib (qtcore) and I don't know how to do.I have built qtbase with command line but it is unuseful...

  • Lifetime Qt Champion

    What problem do you get building from the command line ?

  • @SGaist I have added INCLUDEPATH +="../../include"
    INCLUDEPATH +="../../include/QtCore"
    in the because I had errors on include paths but I have still errors on other include paths:
    In file included from C:\qtsrc\qtbase\src\corelib\animation\qabstractanimation.cpp:143:0:
    C:\qtsrc\qtbase\src\corelib\animation\qabstractanimation_p.h:52:31: fatal error: private/qobject_p.h: No such file or directory
    #include <private/qobject_p.h>

  • Lifetime Qt Champion

    You have to build qtbase from the command line. There's a lot of stuff happening during the build phase of qtbase like header generation. Therefore, build it once and then start hacking on it.

  • @SGaist these problems are only for building with QTCreator.I have no problem to build with command line.but to debug QTCore in QTcreator I must build with QTcreator

  • @SGaist I have built QTbase with command line without problem.But to debug QtCore with QtCreator I must build it with QtCreator.

  • Lifetime Qt Champion

    @stephane78 Your assumption is wrong: you don't have to build with QtCreator to be able to debug in QtCreator. You just need to build a debug version.

  • @jsulm how to debug then ? I have a debug version of Qtbase and I have put the build directory where is the debug version but when I click on the debug button in Qtcreator it tries to build the project....

  • Lifetime Qt Champion

    @stephane78 To debug QtBase you need a project which is linked against it - you cannot execute a library, so you need an executable. Create a project write some code which uses QtBase, put a break point and start debugging. You then can step into QtBase code.

  • @jsulm ok jsuml you are right, I was not able to debug because shadow build was checked.I have unchecked it and now I can I am under windows I must try under windows 10 now and I come back when I have finished.......

Log in to reply