I want to Plot graph by continusly reading from a .txt file. text file contain x and y values . but only taking Y values for Plot and X value is taken as time .It is from Qcustomplot Realtime demo Program .
My first program Plotting single graph from .text file . but after change to continues plotting , it not plotting . Program is attached here
error :
error: no matching function for call to 'QCPGraph::addData(double&, QVector<double>&)'
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->customPlot->addGraph(); // blue line
ui->customPlot->graph(0)->setPen(QPen(QColor(40, 110, 255)));
QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
timeTicker->setTimeFormat("%h:%m:%s");
ui->customPlot->xAxis->setTicker(timeTicker);
ui->customPlot->axisRect()->setupFullAxesBox();
ui->customPlot->yAxis->setRange(10,90);
// make left and bottom axes transfer their ranges to right and top axes:
connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));
// 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
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::realtimeDataSlot()
{
static QTime time(QTime::currentTime());
// calculate two new data points:
double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds
static double lastPointKey = 0;
if (key-lastPointKey > 0.002) // at most add point every 2 ms
{
//QVector<double> x1,y1;
QVector<double> x1, y1;
//open file
QFile file("//home//bananapi//Documents//qttest2//test5//test.txt");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
//get data from file and stored as text stream
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();// read first line and so on
qDebug() << line;
QStringList fields = line.split(';');// split the string
qDebug() << "1:" << fields.at(0).toDouble();
qDebug() << "2:" << fields.at(1).toDouble();
x1.append(fields.at(0).toDouble());
y1.append(fields.at(1).toDouble());
qDebug() << x1;
qDebug() << y1;
}
ui->customPlot->graph(0)->addData(key,y1);
lastPointKey = key;
}
// make key axis range scroll with the data (at a constant range size of 8):
ui->customPlot->xAxis->setRange(key, 8, Qt::AlignRight);
ui->customPlot->replot();
}
Please Help me ...