[SOLVED] QFileSystemWatcher reports change twice



  • Hi,

    on Windows I use the QFileSystemWatcher to watch one file. If I now change this file and press the save button my slot is called through the fileChanged(QString) signal but not only once but twice.
    Any ideas what can cause such a behaviour?

    Thanks



  • Hi,

    some questions:

    Are you sure you using QFileSystemWatcher in the right way? (coudl you post your code?

    This happens for every file? Or for a specified application files (Word, Excel, ....)?

    In any case could you use QFileInfo class to check if really there are something changed in file



  • Here I add the file path to the watcher.

    @watcher.addPath(config->GetFileName().c_str());
    connect(&watcher, SIGNAL(fileChanged(QString)), this,
    SLOT(OnConfigurationFileChanged(QString)));@

    In this case I only have one file with the extension .ini. And the slot is

    @void Core::OnConfigurationFileChanged(QString configFile)
    {
    if (configFile != QString(config->GetFileName().c_str()))
    return;
    LOG_INFO("The configuration has changed. Reload where possible.");
    }@

    It also does not happen everytime but most of the time. So it is quite indeterministic.



  • Hi,

    you should check (using QFileInfo class) if really something is changed (size, permission, time parameters, ....)



  • For some reasons if I use Notepad++ to edit my file it seems that it creates a file because then the size is 0 which the file watcher recognizes. After that the file is written again with content. This will give the second notification.

    I never managed to get this behaviour for example with the Windows editor so it seems to me that this comes from the way notepad++ is writing the files.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.