debugging qml QVector index of out range

98 Views Asked by At

I have been testing some code and it uses QtCharts. I create the line series in QML using

var series = chartView.createSeries(ChartView.SeriesTypeLine, channel , axisX, axisY);

I send this series object to C++ with a signal slot and cast it to a QXYSeries* object:

QXYSeries* xySeries = static_cast<QXYSeries*>(series);

I have a QVector<QPointF> points which gets filled with values and then I populate the points of the series using the replace() function:

xySeries->replace(points)

In my code, I never access the QVector<QPointF> by [] operator.

The code runs fine for a while, then eventually it throws a []operator index out of range assert.

I was unable to debug in Visual Studio, so moved over to Qt Creator and pulled up the stack trace: Screenshot of call stack

It also showed me the index value I believe is throwing the error: enter image description here

However when I looked through the array, it does have a value at index 45000: enter image description here

I'm unsure if I'm using the debugger correctly or even interpreting the values correctly. Any ideas why this assert is being thrown?

Edit: I haven't included a reproducible as the data populating my XYSeries comes from a TCP server so there's just a lot of code to post. Also the assert is being thrown from a Qt file, the call stack shows it traces back to my main which makes sense as that runs my QML files but doesn't specify that any of my own QML files are causing the assert

main.cpp:

{
    QApplication app(argc, argv);
    qmlRegisterType<GuiControl>("com.GuiControl", 1, 0, "GuiControl");  

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/Resources/pages/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);
    
    return app.exec();
}
0

There are 0 best solutions below