QCustomPlot Discussion and Comments

Realtime Plot - Ending graph after more than 24h hoursReturn to overview

Hello.

I have a problem with my temperature measurement. It is QT5 based. I used the real-time example to addData every 100ms to one graph.
I fixed the Range to see always the last hour (3600 sec./1h) and removeBefore (3610 sec.) because I don't want to store the old data.

When i start the application, the plot always works very fine for more than 24 hours, but suddenly the graph ends and runs out of the grid.
I' sure that the code with the addData command will be executed but the graph in not displayed anymore.

Has somebody an idea why this happen or how I can find the mistake?
I tried it with timeticker and datetimeticker, both the same.

Here my code:

void MainWindow::realtimeDataSlot()
{
  static QTime time(QTime::currentTime());
  double key = time.elapsed()/1000.0;                                       // time elapsed since start, in seconds
 
  static double lastPointKey = 0;
  if (key-lastPointKey > 0.0100)                                            // at most add point every 100 ms
  {
    // add data to line:
      ui->widget->graph(0)->addData(key, isttemp);
      ui->widget->graph(0)->data()->removeBefore(key-3610);                 // Alte Werte von vor 3610 Sekunden löschen
    lastPointKey = key;
  }

  ui->widget->xAxis->setRange(key, 3600, Qt::AlignRight);
  ui->widget->replot();
}

------------------------------------------------------------------------------------------------------------------------------------------

void MainWindow::setupRealtimeData(QCustomPlot *customPlot)
{

  customPlot->setBackground(QColor(0xdfdfdf));

  customPlot->addGraph(); // blue line
  customPlot->graph(0)->setPen(QPen(QColor(0x00ab85), 2));

  QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
  timeTicker->setTimeFormat("%h:%m");
  
  customPlot->xAxis->setTicker(timeTicker);
  customPlot->axisRect()->setupFullAxesBox();
  customPlot->yAxis->setRange(0, 40);

  customPlot->xAxis->setLabel("Zeit");
  customPlot->xAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));
  customPlot->yAxis->setLabel("Temperatur ′C");
  customPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));

  // setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
  connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
  dataTimer.start(0); // Interval 0 means to refresh as fast as possible
}

I'll try to reproduce this. In the meantime, could you make a screenshot of this happening and send it to me via email? (see contact page)

//EDIT: Oh I think the problem might be that you use QTime::elapsed. Have a look at the Qt documentation:
http://doc.qt.io/qt-5/qtime.html#elapsed
It wraps to zero after 24 hours since (unlike a QDateTime), a QTime only represents 0:00:00 to 23:59:59. You might want to rather use QElapsedTimer or QDateTime.

Yes.
Switched to QDateTime and everything works well.

Thank you !