[solved] How to make a code to wait while a file is written on hard drive?
-
I imagine 2 different possibilities: (1) the next save() command comes too soon before the previous save() command was completed, or (2) the image changes during the save() operation before save() completed. I do not know which possibility actually realizes, but the code crushes with Fatal IO error 11. Any advise to fix this problem? Thanks.
-
http://doc.qt.nokia.com/4.7/qpixmap.html#save
Since save() blocks until finished as mlong pointed out, the only way for save() to be called
again simultaneously is if it's from another thread. In which case, you will have to make
your code thread-safe, either by using flags/locks or queued slot connections.http://doc.qt.nokia.com/4.7/qtconcurrent.html
http://doc.qt.nokia.com/qq/qq14-threading.html -
There is no much to show, the code is very simple. And it works fine when I need to save a single image. It leads to the crush only when image savings happen very frequently.
@
int AppWind::updateImage()
{
...if (iterCurrent%iterPerOut==0) {
frame2d.saveImage();
...
}
}bool Tp2dFrame::saveImage()
{
QPixmap* pm = getPixmap();
return pm->save(imageFileName);
}
@[EDIT: code formatting, please wrap in @-tags, Volker]
-
Debugging does not help in this case. When doing debugging step-by-step, then everything goes just fine, no crashes, I think because it's not fast enough. If I allow the code to run then it crashes with the error message "Fatal IO error 11 (Resource temporarily unavailable) on X server", and no other information can be obtained.