Solved Can't remove file
-
Hi,
My application extracts a file from it's own resource, but can't remove the created file (because it's read only).
eg: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 ?
Thanks -
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)
-
@Roy44
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
copy()
andremove()
, and usingQFileDevice::FileError QFileDevice::error() const
to discover the reason why. -
It works with new permissions.
thanks