Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to resolve this error ASSERT: “!”No style available without QApplication!“” in file kernel\qapplication.cpp, line 1054?
Forum Updated to NodeBB v4.3 + New Features

How to resolve this error ASSERT: “!”No style available without QApplication!“” in file kernel\qapplication.cpp, line 1054?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Janilson Duarte
    wrote on last edited by
    #1

    When I start application to display a chart it presents me with this error:

    0_1547128795832_bugQT.png

    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 }
         }
      }
    }
    
    raven-worxR J.HilkJ 2 Replies Last reply
    0
    • J Janilson Duarte

      When I start application to display a chart it presents me with this error:

      0_1547128795832_bugQT.png

      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 }
           }
        }
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Janilson-Duarte
      as the error says:
      Instantiate a QApplication instead of a QGuiApplication in your main()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      6
      • J Janilson Duarte

        When I start application to display a chart it presents me with this error:

        0_1547128795832_bugQT.png

        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 }
             }
          }
        }
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Janilson-Duarte
        @raven-worx is right, you have to replace GuiApplication with QApplication, the reason for this is your use of QCharts

        take a look at the docu

        Note: Projects created with Qt Creator's Qt Quick Application wizard are based on the Qt Quick 2 template that uses QGuiApplication by default. All such QGuiApplication instances in the project must be replaced with QApplication as the module depends on Qt's Graphics View Framework for rendering.

        Because QCharts is it's own modul, you'll prob also have to add QT += charts to your project file.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        4
        • J Offline
          J Offline
          Janilson Duarte
          wrote on last edited by
          #4

          Thank you very much guys, it worked.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved