QT5 error: Unknown type name 'QCoreApplication'. First program in Qt5

4.3k views Asked by At

I have just installed QTCreator in Linux Ubuntu 20.04 LTS, I clicked on File->New Project->Application->QTConsole Application. A first.pro file and main.cpp file was made.

The first.pro contains:

QT -= gui declarative
QT += widgets

CONFIG += c++11 console
CONFIG -= app_bundle

DEFINES += QT_DEPRECATED_WARNINGS


SOURCES += \
        main.cpp

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

The main.cpp contains:

 #include <QCoreApplication>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    return a.exec();
}

The error comes in QCoreApplication line.

2

There are 2 answers

0
Colin McGovern On

If the error is an open red circle, the code will still build.

If you want to get rid of the open red circles, go into Help->About Plugins and uncheck the Clang code model plugin. Then restart QT creator.

0
Jorge Luis On

The reason is that new versions of Qtcreator on Ubuntu 20.04 install clang-10, but it still needing clang-8.

Install clang-8 package:

apt install clang-8