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

QML "ChartView" crashing app



  • Hey, I want to use ChartView to show statistics, but when trying to run my app just crashing. I heard about replacing QGuiApplication to QApplication, is it possible? I want QtQuick / QML, not QWidgets.

    :-1: error: Debugger encountered an exception: Exception at 0x3d34d8, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)
    

  • Lifetime Qt Champion

    @BD9a As stated in https://doc.qt.io/qt-5/qapplication.html
    You need

    QT += widgets
    


  • Hi @BD9a,
    I heard about replacing QGuiApplication to QApplication, is it possible?
    Yes, it's possible, change to QApplication, your QtQuict app still works fine!



  • But how? When I just replace

    QGuiApplication app(argc, argv);
    

    to

    QApplication app(argc, argv);
    

    I got error:

    variable has incomplete type 'QApplication'
    

    and more:
    alt text



  • @BD9a
    Did you change to #include <QApplication> ?



  • @JonB Nope, "QApplication file not found". My .pro file have this:

    QT += quick
    QT += quickcontrols2
    

    main.cpp

    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include <Building/building.h>
    #include <Clicking/clicking.h>
    #include <Keytranslator/keytranslator.h>
    #include <Conf/conf.h>
    
    int main(int argc, char *argv[])
    {
    
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
    
        Building building;
        Clicking clicking;
        KeyTranslator ktr;
        Conf config;
    
        building.config = &config;
        clicking.config = &config;
    
        config.create();
    
        building.loopStart();
        clicking.loopStart();
    
        QQmlContext *ctx = engine.rootContext();
        ctx->setContextProperty("Building", &building);
        ctx->setContextProperty("Clicking", &clicking);
        ctx->setContextProperty("keyTranslator", &ktr);
        ctx->setContextProperty("Config", &config);
    
        engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    


  • @BD9a
    I know nothing about QML, only widgets which is where I would do this, given your error message. @Quang-Phu said it was doable/fine, maybe you need clarification from him....


  • Lifetime Qt Champion

    @BD9a As stated in https://doc.qt.io/qt-5/qapplication.html
    You need

    QT += widgets
    


  • Thanks, it's working. I thought it's only QtQuick or QWidgets, not both.


Log in to reply