[solved] How to make a code to wait while a file is written on hard drive?
-
(Please wrap your code in @ tags.)
Have you tried running the program under the debugger to find out exactly where the crash is occurring?
Again, just double checking... this is not running in a separate thread, correct?
-
Actually, there is a question about threads, because AppWind::updateImage() is a time consuming routine and is run by a separate thread. Any advice? Thanks.
-
Is that separate thread using QPixmaps? If it is, that's going to cause you problems.
QImages should be safe, if I remember correctly, though.
-
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.
-
A separate thread calls AppWind::updateImage(), which in turn calls Tp2dFrame::saveImage(), which gets pixmap and saves it to a file: QPixmap* pm = getPixmap(); pm->save(imageFileName);
-
Then you need a traffic cop so cars don't crash into one another at the intersection. See my links above.
-
I tried to use the safe-thread methods as well, by using QMutexLocker locker(&mutex), but nothing helps. Maybe the problem is that the image changes too fast while the save() operation is still in process. Could it cause a crash?
-
Again, if you're using QPixmaps in another thread (or in code that's called from another thread) you're going to have issues, whether you're using mutexes or not.
-
mlong,
I've fixed the problem as you advised: the main thread should operate on QPixmaps. Thank you so much. -
Good deal. Glad to help! Please be sure and edit the title of the thread to add [Solved]. Thanks!