Results 1 to 2 of 2

Thread: Real Time Plot Getting Slower and Slower

  1. #1
    Join Date
    Sep 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Real Time Plot Getting Slower and Slower

    Hi everyone,

    Im a newbie to QT and QWT and required some help. I want to draw a real time plot for sine and cosine wave but my plot get slower and slower when time passes. Any kind soul can help me out? Thank You very much.

    MainWindow Code
    Qt Code:
    1. if(plottingStatus == "play")
    2. {
    3. if(angle1 == 360)
    4. {
    5. timer->stop();
    6. timer->start();
    7. }
    8. else if(angle1 <= 720)
    9. {
    10. if (timer_count%3 == 0)
    11. {
    12. angle1++;
    13. }
    14. timer_count++;
    15.  
    16. //calling the calculation function
    17. if(angle1 == 0 && rotationCount > 0)
    18. {
    19. emit toCalculate(0, timer_count, graphType, passType);
    20. }
    21. else
    22. {
    23. emit toCalculate(harmonics, timer_count, graphType, passType);
    24. }
    25.  
    26. }
    27. else
    28. {
    29. plottingStatus = "stopped1";
    30. rotationCount ++;
    31. timer->stop();
    32. angle1 = 0;
    33. timer_count = 0;
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

    Sine Wave Code
    Qt Code:
    1. theta1 = ((2*n)+1) * 2 * M_PI * timer_count*0.000925925;
    2. amplitude = (1.00/((2*n)+1)*1.00);
    3.  
    4. real = prev_real + (amplitude *(qCos(theta1)));
    5. img = prev_img + (amplitude*(qSin(theta1)));
    6.  
    7. Y = (timer_count*0.000925925);
    8. Y = Y;
    9.  
    10. yData.push_back(img);
    11. xData.push_back(Y);
    12.  
    13. emit graphdata(yData, xData);
    To copy to clipboard, switch view to plain text mode 

    Graphing code
    Qt Code:
    1. cSin = new QwtPlotCurve( "y = sin(x)" );
    2. cSin->setRenderHint( QwtPlotItem::RenderAntialiased, true ); // smoothen the line of graph
    3.  
    4. cSin->setPen( QColor(Qt::green) );
    5. _yData = yData;
    6. _xData = xData;
    7.  
    8. cSin->setSamples(_xData, _yData);
    9. replot();
    10. cSin->attach( this );
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Real Time Plot Getting Slower and Slower

    Hello,

    in your sine wave code you use xData/yData.push_back() to add new values. Have you preallocated (vector::reserve()) a sufficiently big amount of memory to these vectors? If not, the vector will reallocate a bigger chunk of memory when there is not enough memory availabe for storing the new data. When I remember right, std::vector() will duplicate the reserved memory every time a reallocation is necessary. Also note that reallocation requires copying of the already available data from the previous memory location to the new location before freeing the old memory.

    You use emit graphdata(yData, xData) to notify availability of new data. If graphdata() uses value semantics for its parameters, depending on the type of xData and yData a copy of the vectors is created, which again takes time.

    I do not know which class is the client of signal graphdata. Assuming that you have connected some qwt related classes to this signal check if that code walks through the whole data set for plotting the data. Also, do you really need to replot for each new point added to the trace?

    Best regards
    ars

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2013, 06:18
  2. QT is becoming slower ?
    By govi1 in forum Qt Quick
    Replies: 2
    Last Post: 9th October 2012, 01:17
  3. Qwt 6.0.1 three times slower than 5.2.0
    By Spitfire in forum Qwt
    Replies: 13
    Last Post: 26th September 2011, 10:05
  4. Qt 4.6.3 slower than 4.6.2
    By Nik8768 in forum Installation and Deployment
    Replies: 3
    Last Post: 19th July 2010, 12:13
  5. why Qt4 is so slower than Qt3 ?
    By xuyaojun1980 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 11th February 2009, 18:32

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.