Segfault when adding Qwt plot to layout

Deadly 提交于 2019-12-11 19:55:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!