Chartview crashing in QML

Viewed 40

My chartview is crashing in QML - QT Quick application.

This is how my chartview looks like:

import QtQuick 2.15
import QtCharts 2.3
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    GridView
    {
        ChartView {
            title: "Spline"
            anchors.fill: parent
            antialiasing: true

            SplineSeries {
                name: "SplineSeries"
                XYPoint { x: 0; y: 0.0 }
                XYPoint { x: 1.1; y: 3.2 }
                XYPoint { x: 1.9; y: 2.4 }
                XYPoint { x: 2.1; y: 2.1 }
                XYPoint { x: 2.9; y: 2.6 }
                XYPoint { x: 3.4; y: 2.3 }
                XYPoint { x: 4.1; y: 3.1 }
            }
        }
    }
}

This is crashing and not able to launch window

1 Answers

Probably, the segmentation fault is because you need to replace in your main function the QGuiApplication by QApplication. More info.

The following code is working properly:

main.cpp

#include <QApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

main.qml

import QtQuick 2.15
import QtCharts 2.15
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    Rectangle {
        width: 300
        height: 300
        ChartView {
            title: "Spline"
            anchors.fill: parent
            antialiasing: true

            SplineSeries {
                name: "SplineSeries"

                XYPoint { x: 0; y: 0.0 }
                XYPoint { x: 1.1; y: 3.2 }
                XYPoint { x: 1.9; y: 2.4 }
                XYPoint { x: 2.1; y: 2.1 }
                XYPoint { x: 2.9; y: 2.6 }
                XYPoint { x: 3.4; y: 2.3 }
                XYPoint { x: 4.1; y: 3.1 }
            }
        }
    }
}
Related