Results 1 to 4 of 4

Thread: How to delete a file in use? Thanks.

  1. #1
    Join Date
    Aug 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default How to delete a file in use? Thanks.

    Hi, everyone:
    Sorry to bother you, but I need some help here.
    I am working on a reference management project like endnote or jabref. Generally, the main window has two panels. The left panel is a item list and the right panel is a PDF file viewer. When I click an item, it becomes the "current item" and the corresponding attached PDF file stored in a local attachment directory is shown by the PDF viewer on the right panel. The PDF viewer is extracted from TexMaker project which uses poppler library to handle PDF files. When I try to delete the "current item" on the left panel, of course I would like to delete the corresponding PDF attachment as well. However, the PDF file for the "current item" is opened by the PDF viewer, which means it is in use and I couldn't delete it. On Windows, I would get a message like "Could not delete ***: it is been used by another person or program".

    So, could you give me some hints about deleting file even if it is in use? My PDF viewer widget doesn't have a "close file" function and I really don't want to dive into the source code of Texmaker or Poppler.

    Thanks a lot!

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to delete a file in use? Thanks.

    OS denies rights to delete a file if it is currently opened with writing rights. So there is no way you can fix this from qt. However, if the file is opened with ReadONly rights, it should be possible to delete it. In either case, you need to refer to your library on how to open the file in ReadOnly mode.
    By the way, welcome to the forum!!

  3. #3
    Join Date
    Aug 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to delete a file in use? Thanks.

    Thanks for your reply. I solved the problem partially. I use
    QFile.readAll() function to read the PDF file to a buffer before being
    opened by the PDF viewer widget. Thank God poppler-qt4 has implemented
    loadFromData(QByteArray) function. The trick is that one has to close
    QFile after opening it. Some simple tests impress me that if there are
    some IO devices linking to a file, the OS concludes the file is in
    use.
    Of course I don't know how to delete a file used by other programs in
    general. However, it is not my current problem and I could put off it
    to the long long future

  4. #4
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to delete a file in use? Thanks.

    Quote Originally Posted by endring View Post
    Thanks for your reply. I solved the problem partially. I use
    QFile.readAll() function to read the PDF file to a buffer before being
    opened by the PDF viewer widget. Thank God poppler-qt4 has implemented
    loadFromData(QByteArray) function. The trick is that one has to close
    QFile after opening it. Some simple tests impress me that if there are
    some IO devices linking to a file, the OS concludes the file is in
    use.
    Of course I don't know how to delete a file used by other programs in
    general. However, it is not my current problem and I could put off it
    to the long long future
    Generally, you can delete a file, only when all file descriptors associated with your file inode table are deleted. This happens with the deletion of the last fd.

    Cheers,

Similar Threads

  1. delete file with qt
    By dpn in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2013, 14:21
  2. how to delete a file
    By athulms in forum Newbie
    Replies: 2
    Last Post: 13th October 2011, 01:19
  3. delete first row of data from .csv file?
    By babymonsta in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2010, 03:39
  4. how to delete a file?
    By whoops.slo in forum Qt Programming
    Replies: 4
    Last Post: 22nd November 2006, 14:27
  5. How to delete File
    By rajesh in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2006, 11:23

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.