Answer the question
In order to leave comments, you need to log in
It is necessary to add a check whether one class object already exists and in this case remove it from memory and create a new one, what should be done?
The bottom line is that when I click on the button, I call the "drawChart" slot that draws the chart, for this, every time I click the button, I create a new object of the "Chart" class. So the problem is that I can create such objects indefinitely, but I need to delete the old chart and draw a new one when the user clicks on the second / third / etc. button. once.
void MainWindow::drawChart(){
chart = new Chart(line_x0->text().toFloat(), line_yx0->text().toFloat(), this);
layoutChart->addWidget(chart);
layoutMain->addLayout(layoutChart);
}
Answer the question
In order to leave comments, you need to log in
Greetings.
Why not then declare the pointer to the chart as a member of the class, initialize it in the constructor (well, or at the first use), and when you need to draw a new one, just clear the old chart with its own methods, and not recreate it every time anew?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question