How to resolve this ASSERT error: "!" No style available without Qapplication!"" in file kernel qapplication.cpp, line 1054?

Asked

Viewed 169 times

1

When I start an application to display a graph it shows me this error:

inserir a descrição da imagem aqui

QML debugging is enabled. Only use this in a safe Environment. ASSERT: "!" No style available without Qapplication!"" in file kernel qapplication.cpp, line 1054 ASSERT: "!" No style available without Qapplication!"" in file kernel qapplication.cpp, line 1054

/file . pro

    QT += quick
    CONFIG += c++11

    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS

    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

    SOURCES += \
            main.cpp

    RESOURCES += qml.qrc

    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =

    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =

    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

/file . cpp

    #include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

/file . qml

import QtQuick 2.9
import QtQuick.Window 2.2

import QtCharts 2.0
import QtQuick 2.0

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    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 }
        }
    }

}

1 answer

3


Thank you guys, I already found the answer.

To solve this problem, you must replace the Guiapplication for Qapplication, the reason for this is the use of Qcharts

How the documentation on using Qcharts shows link

Note: Projects created with Qt Quick Application from Qt Creator are based on the Qt Quick 2 model that uses Qguiapplication by default. All these instances of Qguiapplication in the project must be replaced by Qapplication, as the module depends on Graphics View Qt framework for rendering.

Since Qcharts is your own module, you will probably have to add charts QT += Charts your project file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.