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

QFileSystemWatcher fileChanged() notifications missed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • None
    • 4.8.2
    • None

    Description

      In the following test case, the watchFiles() function will often hang when invoked on Windows as the QFileSystemWatcher::fileChanged() notification is not always emitted, though the file is modified after the watcher is created. I was not able to reproduce the problem on Mac or Linux.

      void writeRandomDataToFile(const QString& path)
      {
      	QFile file(path);
      	file.open(QIODevice::WriteOnly);
      	QByteArray data;
      	for (int i=0; i < 50; i++) {
      		data.append(qrand());
      	}
      	file.write(data);
      	file.close();
      }
      
      void watchFiles()
      {
      	QString testPath = "test-path.txt";
      	writeRandomDataToFile(testPath);
      	for (int i=0; i < 100; i++) {
      		QFileSystemWatcher watcher;
      		QSignalSpy spy(&watcher, SIGNAL(fileChanged(QString)));
      		watcher.addPath(testPath);
      		writeRandomDataToFile(testPath);
      		while (spy.isEmpty()) {
      			QCoreApplication::processEvents();
      		}
      	}
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            robertknight Robert Knight
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes