问题
I try to build chart demo using Qwt and C++. I've added the following code to button click handler:
QwtPlot *plot = new QwtPlot(QwtText("Demo"));
plot->setGeometry(0, 0, 100, 100);
QwtPlotCurve curve("Sine");
QVector<double> xs;
QVector<double> ys;
for (double x = 0; x < 100; x++)
{
xs.append(x);
ys.append(sin(x));
}
QwtPointArrayData *series = new QwtPointArrayData(xs, ys);
curve.setData(series);
curve.attach(plot);
plot->show();
QLayout *lay = ui->centralWidget->layout();
lay->addWidget(plot);
and it segfaults at addWidget(plot);.
What am I doing wrong?
回答1:
The layout of centralWidget
is probably NULL or you haven't initialized the ui
(e.g. calling setUp()
). Check the first case with if(lay == NULL)
and the second by looking at your code.
If the first case is correct have a look at your UI file in QDesigner and add a layout.
来源:https://stackoverflow.com/questions/9763596/segfault-when-adding-qwt-plot-to-layout