View Full Version : QFile::remove doesn't work
mentalmushroom
20th July 2011, 13:33
Hello. I noticed QFile::remove has problems with deleting files sometimes, namely I can't delete the video file. I think it is somehow related to sharing violation, BUT with WinAPI function DeleteFile it is deleted without any problems, so I suppose there is some bug in QFile. I have this issue always with that file, so it is easy to reproduce.
Sample:
// returns false
QFile::remove("C:/Users/shroom/Documents/TestIt/downloads/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
// returns 1 and deletes fine
DeleteFileA("C:/Users/shroom/Documents/TestIt/downloads/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
I am using Qt 4.7.2 and my operating system is Windows 7 x64
high_flyer
20th July 2011, 13:38
What does permissions return?
QFile::Permissions permissions =QFile::permissions("C:/Users/shroom/Documents/TestIt/downloads/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
mcosta
20th July 2011, 13:41
Print the QIODevice::errorString() to know why QFile::remove fails
mentalmushroom
20th July 2011, 13:49
What does permissions return?
Return zero.
Print the QIODevice::errorString() to know why QFile::remove fails
It prints "No such file or directory", but the file obviously exists.
high_flyer
20th July 2011, 13:58
Return zero.
Which OS are you on?
You probably don't have permission checking on.
Read here on how to do it:
http://doc.qt.nokia.com/latest/qfile.html#Permission-enum
mentalmushroom
20th July 2011, 15:03
Qt 4.7.2 + windows 7 x64. I didn't compile qt from source (downloaded binaries instead).
high_flyer
20th July 2011, 15:17
This is not a change in the Qt source, but in your own code.
This will turn the permission checking on.
Read the doc carefully.
t is possible to force permission checking on NTFS by including the following code in your source:
mentalmushroom
21st July 2011, 10:56
Ok, I changed my code to the following one. Still the same problem.
#include <windows.h>
#include <QtCore>
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
int main(int argc, char *argv[])
{
qt_ntfs_permission_lookup++;
// also tried qt_ntfs_permission_lookup = 1
// returns false
QFile::remove("C:/Users/shroom/Documents/TestIt/downloads/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
// returns 1 and deletes fine
DeleteFileA("C:/Users/shroom/Documents/TestIt/downloads/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
}
high_flyer
21st July 2011, 11:06
Its nice that you turned NTFS permission checking on, but if you don't use it, there is little point in havening it on, right? ;)
Please answer post #2 again, now that permissions is turned on.
Another thing that might be wrong, are the slashes.
Try doubling the slashes and/or reversing them.
mentalmushroom
21st July 2011, 11:47
Ok, perhaps, I don't understand something. How should I "use" those permissions. I try to call f.setPermissions(QFile::WriteOther). For winapi function I don't need any permissions. For other files in the same folder I don't need permissions either, but this seems to be a strange avi file that, I guess, is used by something for preview or another background task. Answer to post #2 is the same: "No such file or directory".
#include <windows.h>
#include <QtCore>
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
int main(int argc, char *argv[])
{
qt_ntfs_permission_lookup++;
// also tried qt_ntfs_permission_lookup = 1
QFile f("C:\\Users\\shroom\\Documents\\TestIt\\downloads\\T he.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK\\The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
f.setPermissions(QFile::WriteOther);
// returns false
f.remove();
// returns 1 and deletes fine
DeleteFileA("C:/Users/shroom/Documents/TestIt/downloads/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK/The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
return 0;
}
VikMorroHun
25th June 2017, 11:54
I had the same problem. I was "this" close to learn how to use Windows API and replace the QFile::remove() function in my code since it doesn't work, when I realized I tried to remove a file with Read Only attribute... Aaahhh... :D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.