Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ChartView with qml



  • I'm trying to use a ChartView on my qml code, like this

    Rectangle {
        anchors.fill: parent
        color:"lightSteelBlue"
        BackEnd{
            id:myBackEnd
        }
        ChartView {
            width: 400
            height: 300
            theme: ChartView.ChartThemeBrownSand
            antialiasing: true
        
            PieSeries {
                id: pieSeries
                PieSlice { label: "eaten"; value: 94.9 }
                PieSlice { label: "not yet eaten"; value: 5.1 }
            }
        }
    
        Button{
    ...
    
    
    //This is my main function
    int main(int argc, char *argv[])
    {
        qmlRegisterType<BackEnd>("BackEnd", 1, 0, "BackEnd" );
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
        mediator *m = new mediator();
    
        QQmlApplicationEngine engine;
        engine.rootContext()->setContextProperty("mediator",m);
    
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    
    
    

    And this is the error I'm receiving
    "ASSERT: "!"No style available without QApplication!"" in file kernel\qapplication.cpp, line 1065"

    I've already try most solutions around internet, none worked


  • Lifetime Qt Champion

    Hi
    And you have the normal main.cpp that creates
    a QApplication instance ?

    #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();
    }
    


  • @mrjj
    no, I had "QGuiApplication app(argc, argv);" instead of " QApplication app(argc, argv);
    " I just changed this line and everything works fine ! thank you!!


Log in to reply