Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCustomPlot how to addData
Qt 6.11 is out! See what's new in the release blog

QCustomPlot how to addData

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 4.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    Hello again!

    I'm having trouble with the following code:

    void MainWindow::graphSelected(QStringList _graphingData) {
        QList<QStringList> list;
        QList<double> data;
        foreach (const QString &s, _graphingData) {
            const QStringList parts = s.split(",");
            list.append(parts);
            Q_ASSERT(parts.size() >= 3);
            data.append(parts.at(2).toDouble());
        }
    
        QVector<double> y = QVector<double>::fromList(data);
    
        if (Debug) {
        qDebug() << list;
        qDebug() << data;
        }
    
        int j = data.size();
        QVector<double> x[j];
    
        for (int i=0; i<j; i++) {
            x[i]<<i;
        }
        customPlot->addGraph();
        customPlot->graph(0)->addData(x, y);  // <- error "no matching function for call to 'QCPGraph::addData(QVector<double> [j], QVector<double>&)'
        customPlot->graph(0)->addData(x, y);
        customPlot->xAxis->setLabel("x - time");
        customPlot->yAxis->setLabel("y - value");
        customPlot->graph(0)->rescaleAxes();
        customPlot->replot();
    }
    

    My understanding is that addData is supposed to take (QVector<T>, QVector<T>). I've spent hours trying to solve this - different data types, different ways of calling it (->setData...), with no luck, so I'm asking for help (again).

    Thanks.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      Hi @MScottM,

      The problem, I suspect, is this line:

      QVector<double> x[j];

      Here you have an array of j vectors of 0 doubles each.

      Instead, do something like:

      QVector<double> x(j);
      

      Which gives a single vector of j doubles.

      Cheers.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        MScottM
        wrote on last edited by
        #3

        Once again @Paul-Colby, that did the trick! That and changing x[i]<<i; back to x[i]=i; I knew it was some kind of rookie mistake.

        It seems to be plotting now, but instead of putting the data on the QWidget that I promoted to a QCustomPlot, it is squishing it up in the corner of my main window...

        0_1514743123620_bf4170c7-bd77-43d0-ad10-a5588c4191d3-image.png

        Have you or anyone seen this behavior, or I could take this to the QCustomPlot support forum...?

        Thanks again for putting me on the right track!

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Are you sure that is the promoted one ?
          From code you say
          customPlot->xxxx
          for a promoted its normally
          ui->customPlot->xxxx

          It seems more like one you NEW and not assign to a layout.

          1 Reply Last reply
          2
          • M Offline
            M Offline
            MScottM
            wrote on last edited by
            #5

            Aha! That was it @mrjj. In my MainWindow setup I had: ui->customPlot = new QCustomPlot(this); I probably put it in there while following some tutorial or other on QCustomPlot.

            Solved!

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved