【问题标题】:Segfault when adding Qwt plot to layout将 Qwt 图添加到布局时出现段错误
【发布时间】:2012-03-19 00:26:11
【问题描述】:

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

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); 处出现段错误。

我做错了什么?

【问题讨论】:

    标签: c++ qt segmentation-fault qwt


    【解决方案1】:

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

    如果第一种情况正确,请在 QDesigner 中查看您的 UI 文件并添加布局。

    【讨论】:

    • 谢谢,lay 真的是 NULL。我在 Designer 中添加了布局,它可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多