[Qt-interest] need some QThread help

Paul Miller paul at fxtech.com
Mon Apr 25 17:31:34 CEST 2011


I'm doing some experimenting with using threading to solve a chicken/egg 
problem I ran into, but I'm not sure of which magic locking class to 
help with the synchronization.

This is a simplified version of the problem. I need to save a rather 
large image (using my own code, not QImage), and I'm saving it 256 lines 
at a time. So I'm pushing 256 lines of data, and I need the thread to 
"consume" the 256 lines and I want the producer to wait for the consumer 
to be finished before it goes to get more lines.

Looking at it from the other side, my consumer is going to write a line 
at a time. I want it to wait for a line to be ready, write the line, 
then go back to waiting. The producer function will be able to provide 
256 lines at once, but should wait for all 256 lines to be consumed 
before returning.

I think a simple semaphore is all I need but my tests so far haven't 
worked right. Any suggestions?



More information about the Qt-interest-old mailing list