diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index 5dd8c057349a2f1b2879f6822b83d4f135cb62e5..995d0c770063925c10dc163262c072a7360c46fc 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -198,13 +198,14 @@ QFileInfo QFileSystemModel::fileInfo(const QModelIndex &index) const
 bool QFileSystemModel::remove(const QModelIndex &aindex)
 {
     const QString path = filePath(aindex);
+    const bool success = QFileInfo(path).isFile() ? QFile::remove(path) : QDir(path).removeRecursively();
 #ifndef QT_NO_FILESYSTEMWATCHER
-    QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
-    d->fileInfoGatherer.removePath(path);
+    if (success) {
+        QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
+        d->fileInfoGatherer.removePath(path);
+    }
 #endif
-    if (QFileInfo(path).isFile())
-        return QFile::remove(path);
-    return QDir(path).removeRecursively();
+    return success;
 }
 
 /*!
@@ -1607,11 +1608,14 @@ bool QFileSystemModel::event(QEvent *event)
 bool QFileSystemModel::rmdir(const QModelIndex &aindex)
 {
     QString path = filePath(aindex);
+    const bool success = QDir().rmdir(path);
 #ifndef QT_NO_FILESYSTEMWATCHER
-    QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
-    d->fileInfoGatherer.removePath(path);
+    if (success) {
+        QFileSystemModelPrivate * d = const_cast<QFileSystemModelPrivate*>(d_func());
+        d->fileInfoGatherer.removePath(path);
+    }
 #endif
-    return QDir().rmdir(path);
+    return success;
 }
 
 /*!
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 3252650d125cfe0cd910316618c5ad4ae135edbc..996d9195913fc300d6513378aef7c244c89efd20 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -123,6 +123,8 @@ private slots:
     void permissions_data();
     void permissions();
 
+    void doNotUnwatchOnFailedRmdir();
+
 protected:
     bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList());
 
@@ -1043,6 +1045,35 @@ void tst_QFileSystemModel::permissions() // checks QTBUG-20503
     QCOMPARE(fileInfoPermissions, modelPermissions);
 }
 
+void tst_QFileSystemModel::doNotUnwatchOnFailedRmdir()
+{
+    const QString tmp = flatDirTestPath;
+
+    QFileSystemModel model;
+
+    const QTemporaryDir tempDir(tmp + '/' + QStringLiteral("doNotUnwatchOnFailedRmdir-XXXXXX"));
+    QVERIFY(tempDir.isValid());
+
+    const QModelIndex rootIndex = model.setRootPath(tempDir.path());
+
+    // create a file in the directory so to prevent it from deletion
+    {
+        QFile file(tempDir.path() + '/' + QStringLiteral("file1"));
+        QVERIFY(file.open(QIODevice::WriteOnly));
+    }
+
+    QCOMPARE(model.rmdir(rootIndex), false);
+
+    // create another file
+    {
+        QFile file(tempDir.path() + '/' + QStringLiteral("file2"));
+        QVERIFY(file.open(QIODevice::WriteOnly));
+    }
+
+    // the model must now detect this second file
+    QTRY_COMPARE(model.rowCount(rootIndex), 2);
+}
+
 
 QTEST_MAIN(tst_QFileSystemModel)
 #include "tst_qfilesystemmodel.moc"