QCustomPlot Discussion and Comments

addData Function.Return to overview


I am trying to use addData function as follows:

void Dialog::setupQuadraticDemo(QCustomPlot *customPlot)
  demoName = "Faisal Demo";
  // generate some data:
  double x[100];
  double y[100];
  //QVector<double> x(501), y(601); // initialize with entries 0..100
  for (int i=0; i<100; ++i)
    x[i] = i/10; // x goes from -1 to 1
    y[i] = i/10;  // let's plot a quadratic function
  // create graph and assign data to it:

  // give the axes some labels:
  // set axes ranges, so we see all data:
  customPlot->xAxis->setRange(0, 10);
  customPlot->yAxis->setRange(0, 10);


and getting the following error:

error: no matching function for call to ‘QCPGraph::addData(double [100], double [100])’

I saw in the QCPCurve class which has QCustom class as friend that this addData is declared like


can somebodly plz tell me what's wrong here in the code.

with regards,
Muhammad Faisal.

based on http://www.qcustomplot.com/documentation/classQCPGraph.html#ab6da6377541fe80d892a9893a92db9c6
addData(const QVector< double > & keys, const QVector< double > & values) accepts vector and appends data. There is another method setData() which also accepts QVector.

@Mostafa Alizadeh,
According to the qcustomplot.h file:
addData is an overloaded function with the following forms:

  void addData(const QCPDataMap &dataMap);
  void addData(const QCPData &data);
  void addData(double key, double value);
  void addData(const QVector<double> &keys, const QVector<double> &values);

With regards,

@Faisal: Exactly. And since you're trying to pass in a variable that is not of the available types, you get a syntax error. (Note that double[] is fundamentally different from double)

@Faisal: you are trying to pass array and it doesn't accepts array and instead you have to pass QVector.