Re: Qwt and thread question
Add a simple signal from main thread that will report when processing has finished and make the secondary thread emit 'finished' only after receiving that signal.
Or cache the list of file names and trigger generating of the report only after all images have been processed.
Re: Qwt and thread question
Thanks I followed your signal approach, and it seems to have solved the problem. However, I have found that 'QwtPlot' method in the main thread is slow and thus blocks the main thread. Is it possible that the plot building is done in the main thread but the plot saving is done in a secondary thread.
Specifically, I want to want to move the following code from the main thread to a secondary thread.
Code:
QwtPlotRenderer renderer;
renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, true);
renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, false);
renderer.
renderDocument(plot, pngfile,
"png",
QSizeF(300,
200),
300);
Will Qwt let me do that?
Re: Qwt and thread question
In general you can render to a QImage in a extra thread, but:
QwtPlot doesn't have a clean separation between a scene and the paint device ( = widget ) , so that many attributes are stored somewhere in the widget or even deeper in its members. For rendering to a different paint devices - with different geometries - a couple of attributes of the widget are temporary modified and reset later. So you might ( probably will ) have races when you try to render to one ( or several images ) and the widget in different threads. ( To support the completely new graphic stack ( = scene graph ) of Qt 5.x I will have to introduce something like a QwtPlotScene anyway - but this won't happen in the next weeks. )
But at least what you can do is to save the rendered images in extra threads, when you render the plot to a QImage and store it yourself - instead of using QwtPlotRenderer::renderDocument. Check the API of QwtPlotRenderer and have a look into the implementation of renderDocument how they are used.
Uwe
PS: better render PDF documents instead of PNGs - scalable vector graphics are preferable in many ways.