Can't remove file
My application extracts a file from it's own resource, but can't remove the created file (because it's read only).
QFile::copy(":/resources/res/line.dwg", "D:/MediaCad/MediaCadQt/win32/debug/temp/line.dwg"); QFile::remove("D:/MediaCad/MediaCadQt/win32/debug/temp/line.dwg");// does not work
How can I fix this ?
Wild guess that you have overlapping actions. The OS did not finish the writing process before you try to delete.
Are those actions adjacent?
When yes, give the OS some time to finish actions.
These actions are not adjacents.
Event after application quit, the file is still read only.
(Sorry for my english)
If it's really true that the file is read-only after copying, under Windows:
file.setPermissions(QFile::ReadOther | QFile::WriteOther); file.remove();
Also you should be checking the returns results of your
remove(), and using
QFileDevice::FileError QFileDevice::error() constto discover the reason why.
It works with new permissions.