From 59f186869c67ab51fccf3aac3153629a1da285b7 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 10 Jun 2011 19:18:03 +0100 Subject: QFileInfoGatherer: call QFileSystemWatcher addPaths from proper thread QFSW isn't thread safe. With removal of the thread inside QFSW, the addPaths and removePaths must be called from the thread the QFSW was created in. Reviewed-by: joao --- src/gui/dialogs/qfileinfogatherer.cpp | 13 +++++++++---- src/gui/dialogs/qfileinfogatherer_p.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gui/dialogs/qfileinfogatherer.cpp b/src/gui/dialogs/qfileinfogatherer.cpp index 315b931..06c9f39 100644 --- a/src/gui/dialogs/qfileinfogatherer.cpp +++ b/src/gui/dialogs/qfileinfogatherer.cpp @@ -170,7 +170,6 @@ void QFileInfoGatherer::updateFile(const QString &filePath) void QFileInfoGatherer::clear() { #ifndef QT_NO_FILESYSTEMWATCHER - QMutexLocker locker(&mutex); watcher->removePaths(watcher->files()); watcher->removePaths(watcher->directories()); #endif @@ -184,11 +183,18 @@ void QFileInfoGatherer::clear() void QFileInfoGatherer::removePath(const QString &path) { #ifndef QT_NO_FILESYSTEMWATCHER - QMutexLocker locker(&mutex); watcher->removePath(path); #endif } +void QFileInfoGatherer::addPath(const QString &path) +{ +#ifndef QT_NO_FILESYSTEMWATCHER + if (!watcher->directories().contains(path)) + watcher->addPath(path); +#endif +} + /* List all files in \a directoryPath @@ -280,10 +286,9 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil { #ifndef QT_NO_FILESYSTEMWATCHER if (files.isEmpty() - && !watcher->directories().contains(path) && !path.isEmpty() && !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) { - watcher->addPath(path); + QMetaObject::invokeMethod(this, "addPath", Q_ARG(QString, path)); } #endif diff --git a/src/gui/dialogs/qfileinfogatherer_p.h b/src/gui/dialogs/qfileinfogatherer_p.h index 98217c1..bff4f69 100644 --- a/src/gui/dialogs/qfileinfogatherer_p.h +++ b/src/gui/dialogs/qfileinfogatherer_p.h @@ -162,6 +162,7 @@ public: void clear(); void removePath(const QString &path); + Q_INVOKABLE void addPath(const QString& path); QExtendedInformation getInfo(const QFileInfo &info) const; public Q_SLOTS: -- cgit v0.12