Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt C++ remove a read only file in windows using

Tags:

c++

qt

I have set a file to be read-only (right click and check readonly). Now when I try to remove the file using the function bool QDir::remove(const QString & fileName) the file is not removed and false is returned.
How do I proceed with this? I have tried fiddling around by changing the permission of the file using QFile::setPermission, but that returns false too.
Can anybody advise an approach for the same?

like image 998
Eternal Learner Avatar asked Mar 31 '11 17:03

Eternal Learner


People also ask

What is QFile QT?

QFile is an I/O device for reading and writing text and binary files and resources. A QFile may be used by itself or, more conveniently, with a QTextStream or QDataStream. The file name is usually passed in the constructor, but it can be set at any time using setFileName().


2 Answers

file.setPermissions(QFile::ReadOther | QFile::WriteOther);
file.remove();

should work.

like image 152
charango Avatar answered Sep 27 '22 19:09

charango


You can set file permissions with QFile

Of course this only for files you have user permission to do. The error may also be because the file is open in another app

like image 40
Martin Beckett Avatar answered Sep 27 '22 20:09

Martin Beckett