Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [Solved] QApplication: No such file or directory
Forum Updated to NodeBB v4.3 + New Features

[Solved] QApplication: No such file or directory

Scheduled Pinned Locked Moved Installation and Deployment
17 Posts 11 Posters 154.8k 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.
  • ZlatomirZ Offline
    ZlatomirZ Offline
    Zlatomir
    wrote on last edited by
    #3

    I think the module isn't added in .pro file, so did you added QT += widgets in your .pro file?

    //anyway if the module is added the header can be included with #include <QApplication> you don't need <QtWidgets/QApplication> or <QtGui/QApplication> in Qt4 (that works with both Qt4 and 5)

    https://forum.qt.io/category/41/romanian

    1 Reply Last reply
    3
    • J Offline
      J Offline
      jalomann
      wrote on last edited by
      #4

      Adding QT += widgets in .pro file made the trick. Thanks.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Carel
        wrote on last edited by
        #5

        Why does qmake not include these, or what must one do in the source to ensure qmake auto generates this line in the .pro file ?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #6

          qmake will never generate anything in your .pro file. Those files are config files for qmake to use, not the other way around. If you create a new project in recent versions of Qt Creator, this line will be added for you in standard app template.

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Carel
            wrote on last edited by
            #7

            Ooh ok, that make more sense now, thanks for the reply.

            Sorry for hijacking the thread by the way :D

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Iotaprime
              wrote on last edited by
              #8

              The "Adding QT += widgets in .pro file" really helped me as well. Thanks.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                realtebo
                wrote on last edited by
                #9

                I'm happy, too. I solved.

                Why qmake --project is doing a so simple task in a wrong way?

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  niboaix
                  wrote on last edited by
                  #10

                  can qmake -project add "QT += widgets" to .pro automatically ?

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Pysis
                    wrote on last edited by
                    #11

                    Just to say what happened to be my problem, it was a dumb error:

                    I was following a guide that had me open an empty QT project, which gave me a .pro file but left it empty. I had filled in some data and "TEMPLATE = application" as they has mentioned it. I already had the "widgets" line but it still couldn't find the library as I included it in the .cpp file. When I changed it to "TEMPALTE = app" the .pro file was parsed, and the file to include resolved correctly (QApplication).

                    1 Reply Last reply
                    0
                    • sierdzioS sierdzio

                      How do you include QApplication header? In Qt5, it resides in <QtWidgets/QApplication>, while in Qt4 it was <QtGui/QApplication>.

                      MijazM Offline
                      MijazM Offline
                      Mijaz
                      wrote on last edited by
                      #12

                      @sierdzio
                      I have add <QtWidgets/QApplication> to mainwindow.h file and
                      QT += widgets in .pro file but still "error : No such file or directory" occurs .

                      jsulmJ 1 Reply Last reply
                      0
                      • MijazM Mijaz

                        @sierdzio
                        I have add <QtWidgets/QApplication> to mainwindow.h file and
                        QT += widgets in .pro file but still "error : No such file or directory" occurs .

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #13

                        @Mijaz said in [Solved] QApplication: No such file or directory:

                        <QtWidgets/QApplication>

                        It's

                        #include <QApplication>
                        

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        MijazM 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @Mijaz said in [Solved] QApplication: No such file or directory:

                          <QtWidgets/QApplication>

                          It's

                          #include <QApplication>
                          
                          MijazM Offline
                          MijazM Offline
                          Mijaz
                          wrote on last edited by
                          #14

                          @jsulm
                          I have changed but error still error not resolved.

                          jsulmJ 1 Reply Last reply
                          0
                          • MijazM Mijaz

                            @jsulm
                            I have changed but error still error not resolved.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #15

                            @Mijaz Please show your pro file and main.cpp

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              braden_sun
                              wrote on last edited by
                              #16

                              @jsulm Hello, I am having a similar issue to @Mijaz. I am trying to use Qt 5.11 to cross compile for a STM32MP157c-DK2 development board. I have successfully loaded images to the board from a qml file but my cpp files are riddled with errors including "use of undeclared identifier 'QCoreApplication'. I have tried adding #include <QApplication> and QT += widgets with no luck. Here is my main.cpp file and my pro file.

                              main.cpp

                              #include <QGuiApplication>
                              #include <QQmlApplicationEngine>
                              
                              #include <QApplication>
                              #include <QLabel>
                              
                              #include <QQmlEngine>
                              #include <QTextCodec>
                              #include <QtGui>
                              
                              int main(int argc, char *argv[])
                              {
                                  QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                              
                                  QGuiApplication app(argc, argv);
                              
                                  QQmlApplicationEngine engine;
                                  const QUrl url(QStringLiteral("qrc:/main.qml"));
                                  QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                                                   &app, [url](QObject *obj, const QUrl &objUrl) {
                                      if (!obj && url == objUrl)
                                          QCoreApplication::exit(-1);
                                  }, Qt::QueuedConnection);
                                  engine.load(url);
                              
                                  return app.exec();
                              }
                              
                              

                              pro file

                              QT += quick widgets core gui
                              
                              CONFIG += c++11 qmltypes qt
                              
                              # The following define makes your compiler emit warnings if you use
                              # any Qt feature that has been marked deprecated (the exact warnings
                              # depend on your compiler). Refer to the documentation for the
                              # deprecated API to know how to port your code away from it.
                              DEFINES += QT_DEPRECATED_WARNINGS
                              
                              # You can also make your code fail to compile if it uses 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
                              TARGET = stm32mp1Test
                                  target.files = stm32mp1Test
                                  target.path = /home/root
                              INSTALLS += target
                              

                              Thanks for the help.

                              jsulmJ 1 Reply Last reply
                              0
                              • B braden_sun

                                @jsulm Hello, I am having a similar issue to @Mijaz. I am trying to use Qt 5.11 to cross compile for a STM32MP157c-DK2 development board. I have successfully loaded images to the board from a qml file but my cpp files are riddled with errors including "use of undeclared identifier 'QCoreApplication'. I have tried adding #include <QApplication> and QT += widgets with no luck. Here is my main.cpp file and my pro file.

                                main.cpp

                                #include <QGuiApplication>
                                #include <QQmlApplicationEngine>
                                
                                #include <QApplication>
                                #include <QLabel>
                                
                                #include <QQmlEngine>
                                #include <QTextCodec>
                                #include <QtGui>
                                
                                int main(int argc, char *argv[])
                                {
                                    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                                
                                    QGuiApplication app(argc, argv);
                                
                                    QQmlApplicationEngine engine;
                                    const QUrl url(QStringLiteral("qrc:/main.qml"));
                                    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                                                     &app, [url](QObject *obj, const QUrl &objUrl) {
                                        if (!obj && url == objUrl)
                                            QCoreApplication::exit(-1);
                                    }, Qt::QueuedConnection);
                                    engine.load(url);
                                
                                    return app.exec();
                                }
                                
                                

                                pro file

                                QT += quick widgets core gui
                                
                                CONFIG += c++11 qmltypes qt
                                
                                # The following define makes your compiler emit warnings if you use
                                # any Qt feature that has been marked deprecated (the exact warnings
                                # depend on your compiler). Refer to the documentation for the
                                # deprecated API to know how to port your code away from it.
                                DEFINES += QT_DEPRECATED_WARNINGS
                                
                                # You can also make your code fail to compile if it uses 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
                                TARGET = stm32mp1Test
                                    target.files = stm32mp1Test
                                    target.path = /home/root
                                INSTALLS += target
                                

                                Thanks for the help.

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                @braden_sun Did you cross compile Qt for your device?
                                Why do you include QApplication and QGuiApplication if you want to use QCoreApplication? You need to include QCoreApplication...

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                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