Question

I have a QVector in which I'm constantly appending data so I can plot on a QwtPlot. But with a high frequency I guess the vector becames too large and the program crashes.

My question is, how can I create a QwtCurve which is only beggining in some point of time, bacause the time that has already passed is not necessary in the vector as it was already plotted.

here's my code:

QVector<double> xv;
QVector<double> cv1;
QVector<double> cv2;

as global variables,

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++;
}
Was it helpful?

Solution

QwtPlotCurve

http://qwt.sourceforge.net/class_qwt_plot_curve.html

inherits from QwtPlotSeriesItem

http://qwt.sourceforge.net/class_qwt_plot_series_item.html

There is a warning in setData

The item takes ownership of the data object, deleting it when its not used anymore.

It probably isn't the fact that you are growing too big... it may be that you are accessing something that Qwt deleted.

Run it in a debugger, and look at the stack trace for where it died, or put in a bunch of qDebug() lines to see where it is dying.

If it is something with the data being too large, you could pop off items off of the head of your vector, before setting the vector.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top