Results 1 to 4 of 4

Thread: Qwt and thread question

  1. #1
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qwt and thread question

    Hi,

    I understand QwtPlotcurve needs to run in the main thread. My plan is to use Qwt for writing out images and have no need of showing images on screen. The image below gives a schematic of my problem.

    My main program has a 'qwt function' to generate images. The file names of these images come from a secondary thread and are sent to the main program via signal/slot mechanism. Once the secondary thread finishes, the list of these filenames are send to a 'write Report' function which uses the filenames and the generated images to write out the report.

    The problem i am facing is that the 'qwt image generating' function is much slower compared to secondary thread. Thus by the time the control reaches to 'write Report' function, the images havent all been generated. Is there any way i can make the secondary thread wait until the 'qwt image generating' function in the main thread has processed all the images.

    Any ideas?
    Attached Images Attached Images

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  3. The following user says thank you to Spitfire for this useful post:

    rajil.s (27th January 2012)

  4. #3
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

    Qt Code:
    1. QwtPlotRenderer renderer;
    2. renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, true);
    3. renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, false);
    4. renderer.renderDocument(plot, pngfile, "png", QSizeF(300, 200), 300);
    To copy to clipboard, switch view to plain text mode 

    Will Qwt let me do that?

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

Similar Threads

  1. qt thread question for different algorithm thread
    By leonardhead in forum Newbie
    Replies: 6
    Last Post: 27th August 2010, 01:10
  2. Thread Design Question
    By craigdillabaugh in forum Qt Programming
    Replies: 4
    Last Post: 30th April 2009, 19:16
  3. thread question
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 15th March 2009, 01:34
  4. QTableWidget Design & Thread Safety Question
    By bpetty in forum Qt Programming
    Replies: 4
    Last Post: 28th March 2008, 00:09
  5. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.