Results 1 to 12 of 12

Thread: detecting that a file is currently being written to...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    22
    Thanked 19 Times in 16 Posts

    Default detecting that a file is currently being written to...

    I need to write a programm that monitors a directory, and upon the arrival of a file, opens it, parses the text, does something with it and moves it to another directory afterwards. During testing the code I encountered that sometimes the content read was empty even though there should be some data.

    After a few hours I found out, that the QFileSystemWatcher emits the signal directoryChanged() as soon as a file start being written to the directory. In case I try to open the file at that very moment, the returned QByteArray is empty. If the file has completely been written to disk however, there is no problem .

    How can I work around this? I could wait a few seconds before opening the file but this is an ugly workaround especially since the file may be larger and a few seconds may not suffice in that case ...


    Thanx in advance

    Edit: What I need is a way to make sure no-one else is writing to the file, before I attempt to open it.
    Last edited by momesana; 30th October 2007 at 17:54.

Similar Threads

  1. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  3. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  4. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  5. Detecting the last empty line in a file
    By Ti_Thom in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2006, 05:14

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
  •  
Qt is a trademark of The Qt Company.