0
我嘗試使用Qwt和C++構建圖表演示。我已將以下代碼添加到按鈕單擊處理程序中:添加Qwt圖佈局時的Segfault
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);處的段錯誤。
我在做什麼錯?
謝謝,lay真的是NULL。我在Designer中添加了佈局,並且它可以工作。 – 2012-03-19 08:20:39