Qt Quick 5.7 ERROR "No style available without QApplication "



  • Hi! Error (windows and ubuntu with last qt 5.7). I created qt quick 2 controls app, add chart 2d bar and try run project, but I've got an error. Look at picture

    It is a bug or I do something wrong?



  • @boniface Does it help if you add

    QT += widgets
    

    to your .pro file, and replace QGuiApplication with QApplication in main.cpp?



  • @jpnurmi Yes, I did, but i have got this error "fatal error C1083: Cannot open include file: 'QApplication': No such file or directory". This error i've got at windows 10, tonight try ubuntu.

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

    }

    pro file

    TEMPLATE = app
    QT += widgets qml quick charts
    CONFIG += c++11
    SOURCES += main.cpp
    RESOURCES += qml.qrc
    include(deployment.pri)



  • @boniface Try re-running qmake. For some reason on Windows it doesn't always happen automatically.



  • This is my .pro file;

    TEMPLATE = app
    
    QT += widgets qml quick charts
    CONFIG += c++11
    
    SOURCES += main.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Default rules for deployment.
    include(deployment.pri)
    

    This is my 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();
    }
    

    This is my .qml file

    import QtQuick 2.0
    import QtCharts 2.0
    
    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 }
        }
    }
    

    and i get the same error , I don't know how to solve it


  • Qt Champions 2016

    @Rivonsen said in Qt Quick 5.7 ERROR "No style available without QApplication ":

    QApplication

    Have you tried using QGuiApplication, which you should use when not dealing with widgets?

    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    
        return QGuiApplication::exec();
    }
    

    With project file:

    TEMPLATE = app
    
    QT += core gui qml quick charts
    CONFIG += c++11
    
    SOURCES += main.cpp
    RESOURCES += qml.qrc
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.