OS: Ubuntu 18.02
GCC version 7.4.0
QMake Version 3.1
Qt Version 5.9.5
QWT Version 6.1.4
Hello Everyone!
I created a qwtplot array, and set a point on origin.
When I delete the qwtplot array before close qt windows, the Qt program is crashed.
The Code is show in the following
mainwindows.h
#include <QMainWindow>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <QPolygonF>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#include <QMainWindow>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <QPolygonF>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QwtPlot *qwtpt;
QPolygonF *polygon;
QwtPlotCurve *curve;
QwtPlotGrid *grid;
QwtSymbol *symbol;
};
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
int numpoints = 10;
initialpoint <<
QPointF(0.0f, 0.0f
);
int k;
for(k = 0; k < numpoints; ++k){
//plot
qwtpt[k].setParent(ui->scrollArea);
qwtpt[k].setGeometry(10, 20 + 181 * k, 760, 161);
qwtpt
[k
].
setAxisTitle(QwtPlot::xBottom,
"points");
qwtpt
[k
].
setAxisTitle(QwtPlot::yLeft,
"efficience %");
qwtpt
[k
].
setAxisScale(QwtPlot::xBottom,
0.0,
132);
qwtpt
[k
].
setAxisScale(QwtPlot::yLeft,
0.0,
100);
qwtpt[k].setStyleSheet(style);
//symbol
symbol
[k
].
setPen(QPen(Qt
::red,
2));
symbol
[k
].
setBrush(QBrush(Qt
::yellow));
symbol
[k
].
setSize(QSize(8,
8));
//curve
curve[k].setPen(Qt::blue, 4);
curve
[k
].
setRenderHint(QwtPlotItem::RenderAntialiased,
true);
curve[k].setSymbol(&symbol[k]);
curve[k].attach(&qwtpt[k]);
curve[k].setSamples(initialpoint);
//grid
grid[k].attach(&qwtpt[k]);
}
}
MainWindow::~MainWindow()
{
delete [] qwtpt; // crash on this line
delete [] polygon;
delete [] curve;
delete [] grid;
delete [] symbol;
delete ui;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
int numpoints = 10;
qwtpt = new QwtPlot[numpoints];
polygon = new QPolygonF[numpoints];
curve = new QwtPlotCurve[numpoints];
grid = new QwtPlotGrid[numpoints];
symbol = new QwtSymbol[numpoints];
QString style = "color: white; ";
QPolygonF initialpoint;
initialpoint << QPointF(0.0f, 0.0f);
int k;
for(k = 0; k < numpoints; ++k){
//plot
qwtpt[k].setParent(ui->scrollArea);
qwtpt[k].setGeometry(10, 20 + 181 * k, 760, 161);
qwtpt[k].setAxisTitle(QwtPlot::xBottom, "points");
qwtpt[k].setAxisTitle(QwtPlot::yLeft, "efficience %");
qwtpt[k].setAxisScale(QwtPlot::xBottom, 0.0, 132);
qwtpt[k].setAxisScale(QwtPlot::yLeft, 0.0, 100);
qwtpt[k].setStyleSheet(style);
//symbol
symbol[k].setPen(QPen(Qt::red, 2));
symbol[k].setStyle(QwtSymbol::Ellipse);
symbol[k].setBrush(QBrush(Qt::yellow));
symbol[k].setSize(QSize(8,8));
//curve
curve[k].setPen(Qt::blue, 4);
curve[k].setRenderHint(QwtPlotItem::RenderAntialiased, true);
curve[k].setSymbol(&symbol[k]);
curve[k].attach(&qwtpt[k]);
curve[k].setSamples(initialpoint);
//grid
grid[k].attach(&qwtpt[k]);
}
}
MainWindow::~MainWindow()
{
delete [] qwtpt; // crash on this line
delete [] polygon;
delete [] curve;
delete [] grid;
delete [] symbol;
delete ui;
}
To copy to clipboard, switch view to plain text mode
if I do not to delete the qwtpt array, the Qt debug show the crash on function ~MainWindow()
if I exchange position between qwtpt and curve, the crash is happened on “delete [] curve”
delete [] curve; // crash on this line
delete [] polygon;
delete [] qwtpt;
delete [] grid;
delete [] symbol;
delete ui;
delete [] curve; // crash on this line
delete [] polygon;
delete [] qwtpt;
delete [] grid;
delete [] symbol;
delete ui;
To copy to clipboard, switch view to plain text mode
Maybe I must to do something before delete the qwtplot array.
Is anyone have idea, or some suggestion for this issues?
Thanks in advance.
Bookmarks