setG-6ren">
gpt4 book ai didi

c++ - 将 Qwt 图添加到布局时出现段错误

转载 作者:行者123 更新时间:2023-11-28 03:39:30 26 4
gpt4 key购买 nike

我尝试使用 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); 处出现段错误。

我做错了什么?

最佳答案

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

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

关于c++ - 将 Qwt 图添加到布局时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9763596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com