Search code examples
qtplotqwt

Weird second line in QwtPlotCurve


I have a text file where I get my values,

I have a timer which works as an increaser to the x axis so the plot is real time.

here's my code.

void gui::x()
{
    int xy = 0;

    QVector<double> x(1000), y(1000);
    FILE *file;

    char line[1024];
    file = fopen("x.txt", "r");

    while (fgets(line,1024,file) != NULL)
    {
        fscanf(file,"%lf %lf", &y[xy], &x[xy]);
        xy++;
    }

    fclose(file);

    QwtPlotCurve *curve = new QwtPlotCurve;
    curve->attach(plot_all[3]);
    curve->setData(y,x);
    curve->

    QwtPlotCurve *curve2 = new QwtPlotCurve;
    curve2->attach(plot[3]);
    curve2->setData(y,x);
}

the proble is i get a weird second line below my plot.

can anyone help me?

ecg


Solution

  • I solved it by using an array instead of a vector.

    void gui::ecg()
    {
        int xy = 0;
    
        double x[1000], y[1000];
        FILE *file;
    
        char line[1024];
        file = fopen("ecg.txt", "r");
    
        while (fgets(line,1024,file) != NULL)
        {
            fscanf(file,"%lf %lf", &y[xy], &x[xy]);
            xy++;
        }
    
        fclose(file);
    
        QwtPlotCurve *curve = new QwtPlotCurve;
        curve->attach(plot_all[0]);
        curve->setData(x,y,1000);
        curve->setPen(QPen(Qt::blue,1));
    
        QwtPlotCurve *curve2 = new QwtPlotCurve;
        curve2->setStyle(QwtPlotCurve::Lines);
        curve2->attach(plot[0]);
        curve2->setData(x,y,1000);
        curve2->setPen(QPen(Qt::blue,1));
    }