添加Qwt图时Segfault布局 [英] Segfault when adding Qwt plot to layout

查看:250
本文介绍了添加Qwt图时Segfault布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Qwt和C ++构建图表演示。我已将以下代码添加到按钮点击处理程序:

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);

,它会在addWidget(plot);

and it segfaults at addWidget(plot);.

我做错了什么?

推荐答案

centralWidget 可能为NULL或您尚未初始化 ui (例如调用 setUp())。使用 if(lay == NULL)检查第一种情况,然后查看您的代码。

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.

第一种情况是正确的看看你的UI文件在QDesigner和添加一个布局。

If the first case is correct have a look at your UI file in QDesigner and add a layout.

这篇关于添加Qwt图时Segfault布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆