Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. I cannot include "QApplication" into a QtQuick project. I'm using Visual Studio 2022.

I cannot include "QApplication" into a QtQuick project. I'm using Visual Studio 2022.

Scheduled Pinned Locked Moved Solved Qt in Education
6 Posts 3 Posters 2.6k Views
  • 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.
  • Z Offline
    Z Offline
    ZeeoTwo
    wrote on 5 Jan 2023, 21:15 last edited by
    #1

    So basically i tried using QtCharts, and i got an error, i found out i need to change my QGuiApplication into QApplication.
    As far as i read on the internet i just had to #include <QtWidgets/qapplication.h>
    and i ended up with code like this:

    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QtWidgets/qapplication.h>`
    
    int main(int argc, char* argv[]) {
    #if defined(Q_OS_WIN)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
        QApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
    
        engine.addImportPath("qrc:/");
    
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    
    

    and it should work. Unfortunately it don't.

    How can i fix this error.?

    My compiler can find this file but it can't find qapplication.cpp where all the definitions are.
    I also do not have any .pro file neither qmake or cmake.

    Do i need to install something in qt maintenance tool (i already installed Qt Charts)
    Do i need to create a new project? (i would preffer not to)

    My Qt version: 6.4.0
    My compiler version: 35ea9c48-527e-40dd-9ebc-293d76d0630c-obraz.png

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TomZ
      wrote on 5 Jan 2023, 21:29 last edited by
      #2

      @ZeeoTwo said in I cannot include "QApplication" into a QtQuick project. I'm using Visual Studio 2022.:

      I also do not have any .pro file neither qmake or cmake.

      So, what buildsystem do you use?

      You likely are simply not using the QWidgets module in your project.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZeeoTwo
        wrote on 5 Jan 2023, 22:54 last edited by
        #3

        @TomZ said in I cannot include "QApplication" into a QtQuick project. I'm using Visual Studio 2022.:

        So, what buildsystem do you use?

        i found this folder in my project:
        db103f37-9ac0-46e0-b7a0-5be4341f238b-image.png
        so qmake i guess but i do not have any qmake file in acctual project folder

        You likely are simply not using the QWidgets module in your project.

        Soo how can i start using it?
        Can i do it simply and fast or do i need to just learn qmake and figure it out?

        J 1 Reply Last reply 6 Jan 2023, 07:01
        0
        • Z ZeeoTwo
          5 Jan 2023, 22:54

          @TomZ said in I cannot include "QApplication" into a QtQuick project. I'm using Visual Studio 2022.:

          So, what buildsystem do you use?

          i found this folder in my project:
          db103f37-9ac0-46e0-b7a0-5be4341f238b-image.png
          so qmake i guess but i do not have any qmake file in acctual project folder

          You likely are simply not using the QWidgets module in your project.

          Soo how can i start using it?
          Can i do it simply and fast or do i need to just learn qmake and figure it out?

          J Online
          J Online
          J.Hilk
          Moderators
          wrote on 6 Jan 2023, 07:01 last edited by
          #4

          @ZeeoTwo there's a QML version of QCharts:
          https://doc.qt.io/qt-6/qtcharts-qmlchart-example.html

          use that one. Don't mix QML and QWidget if you don't have to & also the qml variant is much more performant than the QWidget one


          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.

          Z 1 Reply Last reply 6 Jan 2023, 12:32
          0
          • J J.Hilk
            6 Jan 2023, 07:01

            @ZeeoTwo there's a QML version of QCharts:
            https://doc.qt.io/qt-6/qtcharts-qmlchart-example.html

            use that one. Don't mix QML and QWidget if you don't have to & also the qml variant is much more performant than the QWidget one

            Z Offline
            Z Offline
            ZeeoTwo
            wrote on 6 Jan 2023, 12:32 last edited by
            #5

            @J-Hilk

            @ZeeoTwo there's a QML version of QCharts:

            i know there is a qml version but i can't use it without changing from QGuiApplication to QApplication

            this is my qml file that im loading using loader into my main.qml:

            import QtQuick
            import QtCharts 2.4
            import QtQuick.Controls 2.15
            import QtQuick.Layouts 1.15
            import Config 1.0
                Rectangle{
                    id: home
                
                        ChartView {
                        id: chart
                        title: "Top-5 car brand shares in Finland"
                        anchors.fill: parent
                        legend.alignment: Qt.AlignBottom
                        antialiasing: true
            
                            PieSeries {
                                id: pieSeries
                                PieSlice { label: "Volkswagen"; value: 13.5 }
                                PieSlice { label: "Toyota"; value: 10.9 }
                                PieSlice { label: "Ford"; value: 8.6 }
                                PieSlice { label: "Skoda"; value: 8.2 }
                                PieSlice { label: "Volvo"; value: 6.8 }
                            }
                        }
                }
            
            

            and after running it using QGuiApplication i get:
            8049efaf-64ec-4e61-b331-910f7f7e220c-image.png
            1c1d324b-a89d-40c3-a850-24d48c234f08-image.png

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZeeoTwo
              wrote on 6 Jan 2023, 12:58 last edited by
              #6

              Okay i got it working.
              I'm using Qt Vs Tools extension.
              To make it work i had to open:
              Extensions > Qt VS Tools > Qt Project Settings > Qt Project Settings (on the left) > Qt Modules
              and inside that check QT Widgets.
              I guess this is something like a pseudo .pro file or something.
              and after including #include <QtWidgets/qapplication.h> inside main.cpp
              and changing from QGuiApplication to QApplication inside main.cpp
              everything worked, i got no errors and a chart.

              Thank you for ur time @J-Hilk and @TomZ

              1 Reply Last reply
              1
              • Z ZeeoTwo has marked this topic as solved on 23 Apr 2023, 13:16

              4/6

              6 Jan 2023, 07:01

              • Login

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