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.




Reply With Quote
Bookmarks