Headers QVector<QVector<double> > data_show_C{{100,200,300,4000}, {100,200,300,4000}, {100,200,300,4000}, {100,200,300,4000} };
void Widget::show_C(){ for(int i=0;i<data_show_C.size();i++) //for(int i=data_show_C.size();i>0;i--) { for(int j=0;j<data_show_C[i].size();j++) { qDebug()<<"ddd"<<data_show_C[i][j]; //double z =data_show_C[i][j]; mcolorMap->data()->setCell(i,j,qRound(data_show_C[i][j])); } } }
void Widget::C_plot_init() { ui->customplot_C->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); ui->customplot_C->setBackground(QBrush(Qt::black)); QCPColorMap *mcolorMap = new QCPColorMap(ui->customplot_C->xAxis, ui->customplot_C->yAxis); mcolorMap->data()->setSize(4,4); //mcolorMap->data()->setRange(QCPRange(0,200),QCPRange(0,200)); QCPColorScale *colorScale = new QCPColorScale(ui->customplot_C); colorScale->setType(QCPAxis::atRight); ui->customplot_C->plotLayout()->addElement(0, 1, colorScale); colorScale->setType(QCPAxis::atRight); // scale shall be vertical bar with tick/axis labels right (actually atRight is already the default) mcolorMap->setColorScale(colorScale); mcolorMap->setGradient(QCPColorGradient::gpHot); mcolorMap->rescaleDataRange(true); ui->customplot_C->rescaleAxes(); ui->customplot_C->replot(); }
I have declared a 4*4 Qvector array in the header file myself, The show_C function is called when I click the button,but I get an index out of bounds error when I use the QCPColorMap::setCell function, I can't find where I am going wrong at all, can you help me?
ddd 100 void QCPColorMapData::setCell(int, int, double) index out of bounds: 0 0 ddd 200 void QCPColorMapData::setCell(int, int, double) index out of bounds: 0 1 ddd 300 void QCPColorMapData::setCell(int, int, double) index out of bounds: 0 2 ddd 4000 void QCPColorMapData::setCell(int, int, double) index out of bounds: 0 3 ddd 100 void QCPColorMapData::setCell(int, int, double) index out of bounds: 1 0 ddd 200 void QCPColorMapData::setCell(int, int, double) index out of bounds: 1 1 ddd 300 void QCPColorMapData::setCell(int, int, double) index out of bounds: 1 2 ddd 4000 void QCPColorMapData::setCell(int, int, double) index out of bounds: 1 3 ddd 100 void QCPColorMapData::setCell(int, int, double) index out of bounds: 2 0 ddd 200 void QCPColorMapData::setCell(int, int, double) index out of bounds: 2 1 ddd 300 void QCPColorMapData::setCell(int, int, double) index out of bounds: 2 2 ddd 4000 void QCPColorMapData::setCell(int, int, double) index out of bounds: 2 3 ddd 100 void QCPColorMapData::setCell(int, int, double) index out of bounds: 3 0 ddd 200 void QCPColorMapData::setCell(int, int, double) index out of bounds: 3 1 ddd 300 void QCPColorMapData::setCell(int, int, double) index out of bounds: 3 2 ddd 4000 void QCPColorMapData::setCell(int, int, double) index out of bounds: 3 3