Results 1 to 11 of 11

Thread: QFile::remove doesn't work

  1. #1
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default QFile::remove doesn't work

    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:
    Qt Code:
    1. // returns false
    2. 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");
    3.  
    4. // returns 1 and deletes fine
    5. 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");
    To copy to clipboard, switch view to plain text mode 

    I am using Qt 4.7.2 and my operating system is Windows 7 x64

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFile::remove doesn't work

    What does permissions return?
    Qt Code:
    1. 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");
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::remove doesn't work

    Print the QIODevice::errorString() to know why QFile::remove fails
    A camel can go 14 days without drink,
    I can't!!!

  4. #4
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QFile::remove doesn't work

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFile::remove doesn't work

    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...ermission-enum
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QFile::remove doesn't work

    Qt 4.7.2 + windows 7 x64. I didn't compile qt from source (downloaded binaries instead).

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFile::remove doesn't work

    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:
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. #8
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QFile::remove doesn't work

    Ok, I changed my code to the following one. Still the same problem.
    Qt Code:
    1. #include <windows.h>
    2. #include <QtCore>
    3.  
    4. extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. qt_ntfs_permission_lookup++;
    9. // also tried qt_ntfs_permission_lookup = 1
    10.  
    11. // returns false
    12. 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");
    13.  
    14. // returns 1 and deletes fine
    15. 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");
    16. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QFile::remove doesn't work

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  10. #10
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QFile::remove doesn't work

    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".

    Qt Code:
    1. #include <windows.h>
    2. #include <QtCore>
    3.  
    4. extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. qt_ntfs_permission_lookup++;
    9. // also tried qt_ntfs_permission_lookup = 1
    10.  
    11. QFile f("C:\\Users\\shroom\\Documents\\TestIt\\downloads\\The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3-XviK\\The.Matrix.1999.iNTERNAL.DVDRip.XviD.AC3.CD1-XviK.avi");
    12.  
    13. f.setPermissions(QFile::WriteOther);
    14.  
    15. // returns false
    16. f.remove();
    17.  
    18. // returns 1 and deletes fine
    19. 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");
    20.  
    21. return 0;
    22. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFile::remove doesn't work

    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...

Similar Threads

  1. QFile::remove() strange refresh problem in windows desktop
    By ramazangirgin in forum Qt Programming
    Replies: 6
    Last Post: 8th December 2010, 02:42
  2. Why this code doesn't work?
    By prykHetQuo in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2009, 19:08
  3. remove item for QGirdLayout doesn't work.
    By klnusbaum in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2008, 23:04
  4. Replies: 2
    Last Post: 1st August 2006, 10:23
  5. setWindowOpacity doesn't work!
    By nupul in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2006, 18:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.