我有一个 QVector,我在其中不断附加数据,这样我就可以在 QwtPlot 上绘图。但如果频率很高,我猜 vector 会变得太大并且程序崩溃。
我的问题是,如何创建一个仅在某个时间点开始的 QwtCurve,因为 vector 中不需要已经过去的时间,因为它已经绘制了。
这是我的代码:
QVector<double> xv;
QVector<double> cv1;
QVector<double> cv2;
作为全局变量,
void gui::process_new_info(QByteArray array)
{
int v = 0;
double f = ui->frequency->value();
xv.append(sizeof_array/f);
char *buf = array.data();
if (ui->ecgPlux->isChecked() == true || ui->channel_1->currentIndex() != 0)
{
cv1.append(buf[1]);
QwtPlotCurve *curve1 = new QwtPlotCurve;
curve1->attach(plot_all[0]);
curve1->setData(xv,cv1);
curve1->setPen(QPen(Qt::blue,1));
plot_all[0]->replot();
QwtPlotCurve *curve2 = new QwtPlotCurve;
curve2->attach(plot[0]);
curve2->setData(xv,cv1);
curve2->setPen(QPen(Qt::blue,1));
plot[0]->replot();
}
if (ui->xyzPlux->isChecked() == true || ui->channel_2->currentIndex() != 0)
{
cv2.append(buf[2]);
QwtPlotCurve *curve3 = new QwtPlotCurve;
curve3->attach(plot_all[1]);
curve3->setData(xv,cv2);
curve3->setPen(QPen(Qt::blue,1));
plot_all[0]->replot();
QwtPlotCurve *curve4 = new QwtPlotCurve;
curve4->attach(plot[1]);
curve4->setData(xv,cv1);
curve4->setPen(QPen(Qt::blue,1));
plot[1]->replot();
}
//printf ("%d ->", buf[0]);
fprintf (data, "%d,", buf[0]);
for (int i = 1; i < 9; i++)
{
v = buf[i];
//printf ("%d,", v);
fprintf (data, "%d,", v);
}
//printf ("\n");
fprintf (data, "\n");
sizeof_array++;
}
最佳答案
QwtPlotCurve
http://qwt.sourceforge.net/class_qwt_plot_curve.html
继承自QwtPlotSeriesItem
http://qwt.sourceforge.net/class_qwt_plot_series_item.html
setData
中有警告
The item takes ownership of the data object, deleting it when its not used anymore.
这可能并不是因为您变得太大了……可能是您正在访问 Qwt 删除的某些内容。
在调试器中运行它,然后查看堆栈跟踪以了解它在哪里死亡,或者放入一堆 qDebug()
行以查看它在哪里死亡。
如果数据太大,您可以在设置 vector 之前从 vector 头部弹出项目。
希望有帮助。
关于c++ - 在实时绘图中仅绘制 QwtCurve 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15364132/