I am having some confusion regarding using QVector with QCustomPlot graph->setData. I have some working code, which I have written, and I'm trying to clean things up. There is a function I want to break into multiple functions, and I am having some scope problems. The excerpt below shows a QVector declaration of a few terms which I am manipulating and then sending off to be plotted. The first line in this code function below is the QVector declaration and the graph->seData is in the same scope as this declaration. I am trying to figure out how to get QVecor declaration, manipulation of the data, and presentation (graph-setData(x,y), etc) into seperate functions. The inline code between the QVctor declaration and the graphing is not really important. It is just a bunch of other code Ive written to manipulate the data prior to plotting.
I tried making the QVector global, but that doesn"t seem to work either, so I am pretty confused (maybe doing that wrong too!). How can I keep the declared QVector terms (grapX, graphY, and derivativeY) accessible to the independent functions I want to create?
I realize this this may well be just a neophyte c++ coding problem, and not QCustomPlot specific, but I could sure use some help. Regards, Mark

void MainWindow::buildArrayofScanResults()
QVector<double> graphX(10000), graphY(10000), derivativeY(10000) ;
int samplesCaptured = 0; // initialize counter to 0 for the loop counter
foreach(auto item, arrayOfScanResults.split('\n')) // split on Line Feed
floatArrayOfScanResults[samplesCaptured] = item.toFloat(); // put element in my float array
graphX[samplesCaptured] = samplesCaptured * .0019175; // coeficient for scale to inches
graphY[samplesCaptured] = floatArrayOfScanResults[samplesCaptured];
samplesCaptured++; //iterate index used in building float array

double max_dY = 0;
for(int x=0; x< (samplesCaptured); x++)
.. Do a bunch of (too much) inline code
ui->customPlot->addGraph(); // create graph and assign data to it: