2

I'm tracking a log file that is changed by another application. In linux I receive the fileChanged signal correctly as soon as the other application changes the file. In windows QFileSystemWatcher doesn't emit any fileChanged signal until the other application is closed.

I have tried to open the log with notepad to make sure is actually been changed and as soon as the notepad open the log ,QFileSystemWatcher sends the fileChanged signal.

My code:

void LogLoader::createFileWatcher()
{
    if(fileWatcher != NULL) delete fileWatcher;

    fileWatcher = new QFileSystemWatcher(this);
    connect(fileWatcher, SIGNAL(fileChanged(QString)),
            this, SLOT(prepareLogWorker(QString)));

    if(fileWatcher->addPath(logPath))
    {
        qDebug() << "LogLoader: "<< "FileWatcher linked.";
    }
}


void LogLoader::prepareLogWorker(QString path)
{
    //Added this just in case because I read it as solution
    //in other question. But in my case the file is not removed.
    if (!fileWatcher->files().contains(path))
    {
        fileWatcher->addPath(path);
    }

    QTimer::singleShot(1000, this, SLOT(sendLogWorker()));
}

Am I doing something wrong? Is there any other solution than checking the file manually from time to time?

  • Did you try to open your log file with other application? Does it produce the same behavior? – vahancho Feb 03 '15 at 14:37
  • 1
    Looks like duplicated with http://stackoverflow.com/questions/11669179/qt-qfilesystemwatcher-on-windows – Cui Heng Feb 03 '15 at 14:58
  • I tried to open with chrome and produces the same result. – Pablo Gutiérrez Feb 03 '15 at 17:08
  • I don't think is a duplicate. I do have receive the signals but not while the specific application is writting in the log, not until its closed or I open the log with another tool. – Pablo Gutiérrez Feb 03 '15 at 17:53
  • IMHO, this should be reported to Qt, instead of being asked here. –  Feb 04 '15 at 17:06
  • I can recreate this 100%. I'm wondering if the original poster ever found an answer, since it seems improbable to me that Qt could be so broken on Windows. QFileSystemWatcher seems to work fine on Linux, but the same code does not work at all on Windows. I've found bugs related to the way QFileSystemWatcher does not detect when files are changed when monitoring directories on Windows, but none that say it can't even detect when files are changed (on disk) when monitoring the specific file. Yet, it does not work lest you modify the file with an app that closes the file entirely. – 3vi1 Feb 03 '17 at 03:33

0 Answers0