[C++] How to check if a file is used by another process ?
-
Uhm, you say you want to read the file but in your code snippet you write the file...?
AFAIR there is no native way to check whether a file is still opened or not. You can get notified about changes, but how shall the QFileSystemWatcher know that there will be no further changes in the future?
-
@Johan_R28
I don't know if there is a native way to solve your problem but I think you should read all data and extend your buffer (or process the new data) when a modification was detected. There is no "fileFinallyChanged" signal.
If you have both processes under control you could also try to sync them using a separate IPC (The writing process tells the reading process that the work is done) or by writing the data to a preliminary, temporary file that will be renamed after the file is complete so the reading process will not "see" while the generating is still in progress (just one of many possible ways - the best solution depends on your needs).