diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index ffcd4f36bf..b63f6c1a7e 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -588,13 +589,30 @@ bool FileSystem::remove(const QString &fileName, QString *errorString) // allow that. setFileReadOnly(fileName, false); #endif - QFile f(fileName); - if (!f.remove()) { + + try { + if (!std::filesystem::remove(std::filesystem::path{fileName.toUtf8().data()})) { + if (errorString) { + *errorString = QObject::tr("File is already deleted"); + } + return false; + } + } + catch (const std::filesystem::filesystem_error &e) + { if (errorString) { - *errorString = f.errorString(); + *errorString = QString::fromLatin1(e.what()); } return false; } + catch (...) + { + if (errorString) { + *errorString = QObject::tr("Error deleting the file"); + } + return false; + } + return true; }