@@ -219,7 +219,7 @@ void FileSystemModel::watchDirIfRecursive(const QString& path) {
219219 if (m_recursive && m_watchChanges) {
220220 const auto currentDir = m_dir;
221221 const bool showHidden = m_showHidden;
222- const auto future = QtConcurrent::run ([showHidden, path]() {
222+ auto future = QtConcurrent::run ([showHidden, path]() {
223223 QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot;
224224 if (showHidden) {
225225 filters |= QDir::Hidden;
@@ -232,16 +232,12 @@ void FileSystemModel::watchDirIfRecursive(const QString& path) {
232232 }
233233 return dirs;
234234 });
235- const auto watcher = new QFutureWatcher<QStringList>(this );
236- connect (watcher, &QFutureWatcher<QStringList>::finished, this , [currentDir, showHidden, watcher, this ]() {
237- const auto paths = watcher->result ();
235+ future.then (this , [currentDir, showHidden, this ](const QStringList& paths) {
238236 if (currentDir == m_dir && showHidden == m_showHidden && !paths.isEmpty ()) {
239237 // Ignore if dir or showHidden has changed
240238 m_watcher.addPaths (paths);
241239 }
242- watcher->deleteLater ();
243240 });
244- watcher->setFuture (future);
245241 }
246242}
247243
@@ -295,7 +291,7 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) {
295291 oldPaths << entry->path ();
296292 }
297293
298- const auto future = QtConcurrent::run ([=](QPromise<QPair<QSet<QString>, QSet<QString>>>& promise) {
294+ auto future = QtConcurrent::run ([=](QPromise<QPair<QSet<QString>, QSet<QString>>>& promise) {
299295 const auto flags = recursive ? QDirIterator::Subdirectories : QDirIterator::NoIteratorFlags;
300296
301297 std::optional<QDirIterator> iter;
@@ -353,7 +349,7 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) {
353349 newPaths.insert (path);
354350 }
355351
356- if (promise.isCanceled () || newPaths == oldPaths ) {
352+ if (promise.isCanceled ()) {
357353 return ;
358354 }
359355
@@ -365,23 +361,17 @@ void FileSystemModel::updateEntriesForDir(const QString& dir) {
365361 }
366362 m_futures.insert (dir, future);
367363
368- const auto watcher = new QFutureWatcher<QPair<QSet<QString>, QSet<QString>>>(this );
369-
370- connect (watcher, &QFutureWatcher<QPair<QSet<QString>, QSet<QString>>>::finished, this , [dir, watcher, this ]() {
371- m_futures.remove (dir);
372-
373- if (!watcher->future ().isResultReadyAt (0 )) {
374- watcher->deleteLater ();
375- return ;
376- }
377-
378- const auto result = watcher->result ();
379- applyChanges (result.first , result.second );
380-
381- watcher->deleteLater ();
382- });
383-
384- watcher->setFuture (future);
364+ future
365+ .then (this ,
366+ [dir, this ](QPair<QSet<QString>, QSet<QString>> result) {
367+ m_futures.remove (dir);
368+ if (!result.first .isEmpty () || !result.second .isEmpty ()) {
369+ applyChanges (result.first , result.second );
370+ }
371+ })
372+ .onCanceled (this , [dir, this ]() {
373+ m_futures.remove (dir);
374+ });
385375}
386376
387377void FileSystemModel::applyChanges (const QSet<QString>& removedPaths, const QSet<QString>& addedPaths) {
0 commit comments