I'm learning how to use the plotting and layout system, which has been pretty intuitive so far. In my code I had to separate my sections that sets up the graph window from the part that adds the data. When I did that, for a reason that I can't see right now, my legend stopped adding the names of the plots (it was working before). Now I get a message that says:

bool QCPLayoutGrid::addElement(int, int, QCPLayoutElement*) There is already an element in the specified row/column: 0 1

void QCPLayerable::initializeParentPlot(QCustomPlot*) called with parentPlot zero

By the way I'm reusing most of the code from the tutorial 'user interactions' in order to have that functionality.

Here is my graph setup:

void MainWindow::setUpGraph() {
    ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
                                    QCP::iSelectLegend | QCP::iSelectPlottables);

    QCPLayoutGrid *subLayout = new QCPLayoutGrid;
    ui->customPlot->plotLayout()->addElement(0, 1, subLayout);
    subLayout->addElement(0, 0, new QCPLayoutElement);
    subLayout->addElement(1, 0, ui->customPlot->legend);
    subLayout->addElement(2, 0, new QCPLayoutElement);
    ui->customPlot->plotLayout()->setColumnStretchFactor(1, 0.001);
    QFont legendFont = font();
    ui->customPlot->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items

    // give the axes some labels:
    ui->customPlot->xAxis->setLabel("x - sample # (time)");
    ui->customPlot->yAxis->setLabel("y - value");

    // connect slot that ties some axis selections together (especially opposite axes):
      connect(ui->customPlot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
      // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
      connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
      connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));

      // make bottom and left axes transfer their ranges to top and right 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)));

      // connect some interaction slots:
      connect(ui->customPlot, SIGNAL(axisDoubleClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)), this, SLOT(axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart)));
      connect(ui->customPlot, SIGNAL(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*,QMouseEvent*)), this, SLOT(legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*)));
      //connect(title, SIGNAL(doubleClicked(QMouseEvent*)), this, SLOT(titleDoubleClick(QMouseEvent*)));

      // connect slot that shows a message in the status bar when a graph is clicked:
      connect(ui->customPlot, SIGNAL(plottableClick(QCPAbstractPlottable*,int,QMouseEvent*)), this, SLOT(graphClicked(QCPAbstractPlottable*,int)));

      // setup policy and connect slot for context menu popup:
      connect(ui->customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));

And adding the data:

void MainWindow::graphSelected(QStringList _graphingData, QString sensorName) {
    QList<QStringList> list;
    QList<double> dataPoints;
    foreach (const QString &s, _graphingData) {
        const QStringList parts = s.split(",");
        Q_ASSERT(parts.size() >= 3);
    QVector<double> y = QVector<double>::fromList(dataPoints);
    if (Debug) {
        qDebug() << list;
        qDebug() << dataPoints;
    int j = dataPoints.size();
    QVector<double> x(j);
    for (int i=0; i<j; i++) {

    ui->customPlot->graph()->addData(x, y);
    QPen graphPen;
      graphPen.setColor(QColor(rand()%245+10, rand()%245+10, rand()%245+10));
      // set axes ranges, so we see all data:

Can anyone help zero in on my problem? Or point out any other issues (I freely admit to needing more practice with coding).