gpt4 book ai didi

c++ - 在实时图中仅绘制 QwtCurve 的一部分

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:51:39 25 4
gpt4 key购买 nike

我有一个 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/

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