1

I need help. Here is my code (i show main part):

// Arduino Reader

    serial.setPortName("/dev/ttyACM0");
    serial.open(QIODevice::ReadWrite);
    serial.setBaudRate(QSerialPort::Baud9600);
    serial.setDataBits(QSerialPort::Data8);
    serial.setParity(QSerialPort::NoParity);
    serial.setStopBits(QSerialPort::OneStop);
    serial.setFlowControl(QSerialPort::NoFlowControl);
    connect(&serial,SIGNAL(readyRead()),this,SLOT(getNewData()));

...

void MainWindow::getNewData()
{
    std::clock_t starter = std::clock();
    QByteArray data = serial.readAll();
    QDataStream in(serial.readAll());
    getData = getData + data;

    int start = getData.indexOf(":START:");
    int end = getData.indexOf(":END:",start);
    QString nowWork = getData.mid(start,end-start+5);
    if (nowWork.startsWith(":START:") && nowWork.endsWith(":END:")){
        QStringList mod = nowWork.remove(":START:").remove(":END:").split(":");
        int xPoint = mod[0].toInt();
        int yPoint = mod[1].toInt();
        int zPoint = mod[2].toInt();
        int aPoint = mod[3].toInt();
        int bPoint = mod[4].toInt();
        int cPoint = mod[5].toInt();
        addQuery(1,xPoint,yPoint,zPoint);
        addQuery(2,aPoint,bPoint,cPoint);
        getData = getData.right(end+5);
    }
    std::clock_t ender = std::clock();
    ui->ping->setText(QString::number( (ender-starter)/ (double)CLOCKS_PER_SEC *100));
    return;
}

...

 void MainWindow::addQuery(int to, int x, int y, int z){
        seriesAllD1->append(now, (x+y+z)/3 );
        seriesXD1->append(now,x);
        seriesYD1->append(now,y);
        seriesZD1->append(now,z);
        seriesAllD1->remove(0);
        seriesXD1->remove(0);
        seriesYD1->remove(0);
        seriesZD1->remove(0);
        chartAllD1->axisX()->setRange(now-100,now);
        chartX->axisX()->setRange(now-100,now);
        chartY->axisX()->setRange(now-100,now);
        chartZ->axisX()->setRange(now-100,now);
        now++;
        return;
    }

I try to describe code: 1) It gets data from arduino (Like a ":START:X:Y:Z:A:B:C:END::START:..."). 2) It gets indicates from 2-sensors (3-axis accelometr). And draws Graphs.

I show some code block. After adding ~900 point it gets slow from 60 ms to 1000 ms. I think it is related to QtChart (i use them in project) or addind points to series. Please help me(

Abushkin17
  • 11
  • 2

1 Answers1

0

This is an old topic - however I also ran into it when working with QtCharts - so: for others who will stumble on the same problems with QtCharts and would also like to use QtCharts here are my solutions:

Use OpenGL:

  • call setUseOpenGL(true) on the series in the plot (will only work with QLineSeries and QScatterSeries) - unfortunately this is not the default, but it could be a problem on some systems

When not using OpenGL (i.e. also using QAreaSeries):

And this special trick a colleague came up with when working with real time data:

  • set all series to signalsBlocked(true), start a timer when blocking, unblock after a second, block again and start timer when adding new data again - this will update the plots on (about) every second, but the performance impact is low
michael_s
  • 2,515
  • 18
  • 24