QFile::setPermissions(0)
clears all permissions as it does chmod
on Linux.
Update for Windows
According to Qt QFile documentation:
Qt's understanding of file permissions is limited, which affects
especially the QFile::setPermissions()
function. On Windows, Qt will
set only the legacy read-only flag, and that only when none of the
Write* flags are passed. Qt does not manipulate access control lists
(ACLs), which makes this function mostly useless for NTFS volumes. It
may still be of use for USB sticks that use VFAT file systems. POSIX
ACLs are not manipulated, either.
So, on Windows it is possible to set or unset legacy read-only flag using QFile::setPermissions()
.
Usage of that feature is also tricky. To set the read-only flag only some `Read* permission should be configured. However, to remove that flag a write permission should be added, for example:
// set Windows read-only file flag
file.setPermissions(QFile::ReadOther);
// remove Windows read-only file flag
file.setPermissions(QFile::ReadOther | QFile::WriteOther);
The last trick I found in the answer to Qt C++ remove a read only file in windows using