c++ - `fatal error: QApplication: No such file or directory` persists - Stack Overflow

I am dealing with a fatal error: QApplication: No such file or directory, similar to this and this post

I am dealing with a fatal error: QApplication: No such file or directory, similar to this and this post. I have attempted the proposed solutions with no avail. I am running the code using wsl on Windows 10, which is to say that to run the code I

  1. Navigate to the project's folder.

  2. Open the command prompt.

  3. Run > wsl

  4. Run $ code .

  5. After VSCode opens, I open a new terminal and run

    $ qmake -project
    $ qmake
    $ make
    

The output of which is

g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB - 
DQT_CORE_LIB -I. -I. -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o Main.o Main.cpp
Main.cpp:1:10: fatal error: QApplication: No such file or directory
    1 | #include <QApplication>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1275: Main.o] Error 1

A few things I have tried or verified:

  1. The newest versions of qmake and Qt are installed:

    $ qmake -v
    QMake version 3.1
    Using Qt version 5.15.13 in /usr/lib/x86_64-linux-gnu
    
  2. My .pro file contains all necessary lines, the first couple being:

    QT += core gui
    QT += widgets
    
  3. Checking the location of Qt:

    $ qmake -query QT_INSTALL_HEADERS
    /usr/include/x86_64-linux-gnu/qt5
    

and manually forcing the .pro file to include Qt by adding the following lines to the .pro:

INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtWidgets
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtCore
  1. Using pkg-config, by adding the lines

    CONFIG += link_pkgconfig
    PKGCONFIG += Qt5Widgets Qt5Gui Qt5Core
    QMAKE_CXXFLAGS += -fPIC
    

to the .pro and running

$ qmake
$ make clean
$ make

I am dealing with a fatal error: QApplication: No such file or directory, similar to this and this post. I have attempted the proposed solutions with no avail. I am running the code using wsl on Windows 10, which is to say that to run the code I

  1. Navigate to the project's folder.

  2. Open the command prompt.

  3. Run > wsl

  4. Run $ code .

  5. After VSCode opens, I open a new terminal and run

    $ qmake -project
    $ qmake
    $ make
    

The output of which is

g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB - 
DQT_CORE_LIB -I. -I. -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o Main.o Main.cpp
Main.cpp:1:10: fatal error: QApplication: No such file or directory
    1 | #include <QApplication>
      |          ^~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:1275: Main.o] Error 1

A few things I have tried or verified:

  1. The newest versions of qmake and Qt are installed:

    $ qmake -v
    QMake version 3.1
    Using Qt version 5.15.13 in /usr/lib/x86_64-linux-gnu
    
  2. My .pro file contains all necessary lines, the first couple being:

    QT += core gui
    QT += widgets
    
  3. Checking the location of Qt:

    $ qmake -query QT_INSTALL_HEADERS
    /usr/include/x86_64-linux-gnu/qt5
    

and manually forcing the .pro file to include Qt by adding the following lines to the .pro:

INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtWidgets
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtCore
  1. Using pkg-config, by adding the lines

    CONFIG += link_pkgconfig
    PKGCONFIG += Qt5Widgets Qt5Gui Qt5Core
    QMAKE_CXXFLAGS += -fPIC
    

to the .pro and running

$ qmake
$ make clean
$ make
Share Improve this question edited Mar 4 at 12:01 Sam asked Mar 4 at 2:02 SamSam 4761 gold badge5 silver badges19 bronze badges 7
  • TheQApplication file should be in the /usr/include/x86_64-linux-gnu/qt5/QtWidgets folder I believe (or at least its in a similar location on my Gentoo server). I typed find /usr/include/qt5 -name 'QApplication' because qmake -query QT_INSTALL_HEADERSreturned /usr/include/qt5 – drescherjm Commented Mar 4 at 3:23
  • How did you install qt? If you used the Ubuntu packages ensure that you've installed all of them, qt is broken up into many packages, I'd guess you've only installed the core packages and not all of the libraries – Alan Birtles Commented Mar 4 at 7:17
  • @AlanBirtles and headers are part of dev packages while qmake is separate – Swift - Friday Pie Commented Mar 4 at 8:43
  • Might be aproblem with WSL Extension for VS configuration or with WSL environment itself. Did you try t open WSl terminal and check if all files are there? – Swift - Friday Pie Commented Mar 4 at 8:45
  • @drescherjm running find /usr/include/x86_64-linux-gnu/qt5 -name QApplication gives /usr/include/x86_64-linux-gnu/qt5/QtWidgets/QApplication. As shown in the post, the /usr/include/x86_64-linux-gnu/qt5 directory is included in the .pro, so it should be able to find QApplication, right? – Sam Commented Mar 4 at 11:23
 |  Show 2 more comments

1 Answer 1

Reset to default 0

With Qt 5 and 6 I have had to also add QtWidgets/ to the #include <> to access QApplication.

#include <QtWidgets/QApplication>

Also mentioned here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745064405a4609166.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信