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?
The layout of
centralWidget
is probably NULL or you haven't initialized theui
(e.g. callingsetUp()
). Check the first case withif(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.