diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 5f91ce5e3d..3b67dd61c7 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -403,6 +403,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath(); const uint flags = isDir ? (FILE_NOTIFY_CHANGE_DIR_NAME + | FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_FILE_NAME) : (FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_FILE_NAME diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index cdd1f6361e..7d88601e54 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -34,6 +34,9 @@ #include #include #include +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +#include +#endif /* All tests need to run in temporary directories not used * by the application to avoid non-deterministic failures on Windows @@ -79,6 +82,9 @@ private slots: void signalsEmittedAfterFileMoved(); void watchUnicodeCharacters(); +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + void watchDirectoryAttributeChanges(); +#endif private: QString m_tempDirPattern; @@ -813,5 +819,27 @@ void tst_QFileSystemWatcher::watchUnicodeCharacters() QTRY_COMPARE(changedSpy.count(), 1); } +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +void tst_QFileSystemWatcher::watchDirectoryAttributeChanges() +{ + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); + + QDir testDir(temporaryDirectory.path()); + const QString subDir(QString::fromLatin1("attrib_test")); + QVERIFY(testDir.mkdir(subDir)); + testDir = QDir(temporaryDirectory.path() + QDir::separator() + subDir); + + QFileSystemWatcher watcher; + QVERIFY(watcher.addPath(temporaryDirectory.path())); + FileSystemWatcherSpy changedSpy(&watcher, FileSystemWatcherSpy::SpyOnDirectoryChanged); + QCOMPARE(changedSpy.count(), 0); + QVERIFY(SetFileAttributes(reinterpret_cast(testDir.absolutePath().utf16()), FILE_ATTRIBUTE_HIDDEN) != 0); + QTRY_COMPARE(changedSpy.count(), 1); + QVERIFY(SetFileAttributes(reinterpret_cast(testDir.absolutePath().utf16()), FILE_ATTRIBUTE_NORMAL) != 0); + QTRY_COMPARE(changedSpy.count(), 2); +} +#endif + QTEST_MAIN(tst_QFileSystemWatcher) #include "tst_qfilesystemwatcher.moc"