Results 1 to 6 of 6

Thread: Updating QPlot's curve with Qthread

  1. #1
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Updating QPlot's curve with Qthread

    Pardon me, I am new here.

    There's been similar threads with similar problem, but there's yet real answer.

    I have a class which contains both QwtPlot, QwtPlotCurve and its array of data. I have certain function to update 'em.

    Calling the function manually yields the desired result: last value of graph is updated while data are shifted to 'front'.



    Qt Code:
    1. xGraph->updateCurve(xGraph->getValue()+2.4);
    2. xGraph->updateCurve(xGraph->getValue()+3.4);
    3. xGraph->updateCurve(xGraph->getValue()-9.8);
    4. xGraph->updateCurve(xGraph->getValue()+2.8);....
    To copy to clipboard, switch view to plain text mode 

    But using QThread (which I badly need to update the plot realtime), after I started the thread, the plot's just updated once. It's also no luck with me with QTimer timeout() signal--it yields similar result.

    Qt Code:
    1. class graphthread : public QThread{
    2. public:
    3. graphs *yeah;
    4.  
    5. graphthread(graphs *hereitis){
    6. yeah=hereitis;
    7. }
    8.  
    9. void run(){
    10. while (1){
    11. yeah->updateCurve(yeah->getValue()+0.4);
    12. // printf("%f\n",yeah->getValue()); // the plot won't update but this's repeatedly printed
    13. msleep(2000);
    14. }
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 


    note that there's little elevation in the rightmost

    'd anyone like to show me where I am doing wrong?
    Any help would be appreciated.
    Last edited by jendral_hxr; 25th May 2011 at 00:18.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QPlot's curve with Qthread

    I am not very sure of Qwt, but I thing I suspect is that, "graphs *hereitis" is the QThread's constructor parameter which is stored in "yeah" member variable, an then it is used later in the context of the QThread.

    Now internally yeah->updateCurve(..) might be emitting some signals which need to propagated to the GUI thread, only then the graph will be updated. You may not be able to make signals work until the "graphs" object (yeah) is created in the context of the working Thread, or at least the working thread has the ownership.

  3. #3
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Updating QPlot's curve with Qthread

    Ah, yep. So I need to make SIGNAL which triggers certain GUI-related (widget) SLOT?
    And I am sorry, the variable names should have been clearer
    Last edited by jendral_hxr; 26th May 2011 at 05:10.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Updating QPlot's curve with Qthread

    I mean who is owner of the graph, QwtPlot and QwtPlotCurve class objects?

  5. #5
    Join Date
    Feb 2011
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Updating QPlot's curve with Qthread

    The 'owner' the QwtPlot, QwtPlotCurve is a class I made myself.

    After reading queuedcustomtype example, it's clear to me: I need to make a SIGNAL in a thread to pass some value to a SLOT of widget which has that 'updating' thread So every self-updating widget has to have its own thread within?

    Thanks, Santosh Reddy

    ummh, it's just embarrassing that the title is QPlot instead of QwtPlot, duh!
    Last edited by jendral_hxr; 27th May 2011 at 15:27.

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

    Default Re: Updating QPlot's curve with Qthread

    For any type of "realtime" plot I strongly recommend to decouple the refresh rate of your plot widget from the sample rate.

    Use a QTimer, that periodically checks if new samples have been collected and calls replot then.

    Uwe

Similar Threads

  1. Updating QwtPlot from QThread
    By atzengin in forum Newbie
    Replies: 3
    Last Post: 5th April 2012, 09:05
  2. Replies: 4
    Last Post: 29th April 2010, 07:11
  3. Replies: 1
    Last Post: 22nd January 2010, 15:34
  4. Replies: 4
    Last Post: 26th June 2008, 19:41
  5. Replies: 15
    Last Post: 8th May 2007, 12:46

Tags for this Thread

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.