Qt Creator 无法正确解析包含文件并显示大量错误

Lor*_*nDB 1 ide qt qt-creator

Qt Creator 没有正确解析我的项目中的包含文件,并在 IDE 中给出很多错误,包括main.cpp:14:5: error: unknown type name 'QApplication'. 然而,我的项目编译得很好。我厌倦了所有这些假定的错误,并且想知道是否有任何方法可以解决此问题。

我的 .pro 文件如下所示:

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
Run Code Online (Sandbox Code Playgroud)

几天前我有一种预感(我完全忘记了我是如何得到这种预感的),这stddef.h导致了问题。所以我添加#include <stddef.h>到我的 main.cpp 中,Qt Creator 给出了错误:

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

其中“{”是命名空间 std 中的开头 {。

Lor*_*nDB 8

Qt 论坛上的有人告诉我转到帮助菜单 > 关于插件 > 禁用 ClangCodeModel 插件。这需要重新启动 Qt Creator,但它解决了我的问题。