PDA

View Full Version : Blocking file access



K.Sejdak
20th June 2011, 13:15
Is there a way to somehow block a file on Windows XP by Qt function? I mean to prevent from modification by other program/device until my program unlocks it.

Santosh Reddy
20th June 2011, 21:14
just try renaming the file to a temp name and revert it back when done...:cool:

stampede
20th June 2011, 21:26
A workaround could be to open the file in QIODevice::ReadWrite mode, it should prevent it from being written elsewhere.

Talei
20th June 2011, 21:46
In addition see this link (http://en.wikipedia.org/wiki/File_locking) about file locking.

K.Sejdak
27th June 2011, 09:13
Thanks for your help. I have decided to change the filename each time I want to block it and after that delete it. I will explain why:
My app has to present picture which is loaded in loop by camera over FTP. When picture is ready to read (loaded on disk) camera sends signal over GPIO port to my app, but still there is no guarantee that when I start reading it camera won't start loading next picture. There is no physical way to synchonize my thread and device, because all pins are busy. The problem is that from time to time my app loads half of an old image and half of a new one. This solution IMHO will work, because right after signal detection I will change the filename and even if camera starts loading another picture, it will create new file on disk. When I finish my job i simply delete file and wait for another signal.