Search code examples
qtideqt-creator

Qt Creator isn't parsing include files properly and displays lots of errors


Qt Creator is not parsing the include files in my project properly and gives a lot of errors in the IDE, including errors like main.cpp:14:5: error: unknown type name 'QApplication'. However, my project compiles perfectly fine. I am getting tired of all these supposed errors and am wondering if there is any way to fix this issue.

My .pro file looks like this:

QT += core gui widgets
# 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). 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 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 += \
    klocktimer.cpp \
    main.cpp \
    klockmainwindow.cpp \
    chronometer.cpp

TRANSLATIONS += \
    klock_en_US.ts \
    klock_es_MX.ts

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

HEADERS += \
    klocktimer.h \
    klockmainwindow.h \
    chronometer.h

I had a hunch from a few days ago (I forget exactly how I got this hunch) that stddef.h was causing the problem. So I added #include <stddef.h> to my main.cpp, and Qt Creator gave the error:

/home/loren/code/klock/main.cpp:12: error: 'stddef.h' file not found
/usr/include/c++/9/ostream:42: to match this '{'

where the '{' is the beginning { in namespace std.


Solution

  • mrjj said on Qt Form — Qt Creator Not Correctly Parsing Includes:

    Maybe its the code model that is acting up ?
    Could try disable it for a moment ?
    menu: Help->About Plugins then

    and restart creator. then open and see if includes are still red.


    In 2022, the problem is now fixed, so it's possible to have ClangCodeModel enabled for C++20 syntax support without having this problem.