Hey, I have an application showing a plot in a window. The plot can be opened in a different window when double-clicked on where filtering settings can be altered and re-applied.

Currently the way I display the plot in the second window is by copying the former plot data an re-creating it in the new window.

So what I would like to do is somehow have the same plot instance in the second window so that when data is changed in the second window it will also be changed in the former window.

Sorry if the following code is a bit pseudo-ish, I renamed most of the variables for privacy.

Here is how I open the second window:

void former_window_interface::onPlotDoubleClicked(dataStruct plotData)
{
    second_window_interface* w = new second_window_interface(plotData);
    w->setWindowFlag(Qt::Window);
    w->show();
}

I would like this part to look like something this instead:

void former_window_interface::onPlotDoubleClicked(QCustomPlot* plot)
{
    second_window_interface* w = new second_window_interface(plot);
    w->setWindowFlag(Qt::Window);
    w->show();
}

Here's how I recreate the plot in when the second window is initialized:

second_window_interface::second_window_interface(dataStruct plotData, QWidget* parent) : QWidget(parent)
{
    ui.setupUi(this);
    setupPlot(ui.qPlot); // Adds same no. of graph layers, titles et.c. It sets up the skeleton of the plot
    drawPlot(ui.qPlot, plotData; // Plots all curves taken from plotData
    ui.qPlot->replot();
}

I would like this part to look something like this instead, this is the part I have issues with and am not sure how I should do:

second_window_interface::second_window_interface(QCustomPlot* plot, QWidget* parent) : QWidget(parent)
{
    ui.setupUi(this);
    ui.qPlot = plot;
    ui.qPlot->replot();
}

I am unsure if it is possible to transfer the plot instance between windows like this. I think I have it figured out how to have the instance relayed to the second window, but now i want to display this plot in the second window. Perhaps I can do away with the ui.qPlot entirely and do something with the plot directly in the second window?

I am thankful for all the help and hints I can get!