QLineSeries sigsegv when append a new point

753 views Asked by At

I was developping a datalogging application with Qt Creator (Qt 5.9) and I wanted to add a graph with the help of QtCharts.

I explain what I do: I begin to declare my line as a global variable:

QLineSeries *serie;

In the loop of creating the mainwindow, I create a chart, standard axis and all I need to view the line where I want.

QChart *chart = new QChart();
chart->setTitle("Données accélération");
chart->setAnimationOptions(QChart::AllAnimations);
QChartView *chartView = new QChartView(chart);
chartView->setMinimumWidth(700);
chartView->setRenderHint(QPainter::Antialiasing);
ui->gridLayout_2->addWidget(chartView,0,3,3,1);
QLineSeries *serie = new QLineSeries();
//QSplineSeries *serie = new QSplineSeries();
serie->append(QPointF(50, 50));
serie->append(QPointF(55, 55));
QPen green(Qt::red);
green.setWidth(3);
serie->setPen(green);
chart->addSeries(serie);
chart->createDefaultAxes();

In another function, I use a serialevent to make some choices depending on a switch:

case acquisition :  
reely = (recev_message.toInt())/1000;
reelx = index+1;
qDebug() << reely;
serie->append(reelx, reely);
index++;

After a freeze when I received a serial message, I launched a debug. And it seems that a SIGSEGV append at the step serie->append(reelx, reely);

I don't understand why I can't append a new value when in the example programs for Qtcharts it seems to work.

Thank you for your reading.

1

There are 1 answers

0
Prof_Sims On BEST ANSWER

I found where is the problem.

I effectively declared the serie as a global variable. But in the mainvindow building function I wrote:

QLineSeries *serie = new QLineSeries();

It seems that the compiler deducted that I was re-declaring the object and changed the scope of it. And when I tried to use one of the members in another function, I wasn't in the right scope

So, I changed by that line:

serie = new QLineSeries();

And everything work like a charm.

Thanks to everybody