首页 > 解决方案 > 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

几天前我有一种预感(我完全忘记了我是如何得到这种预感的),这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 '{'

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

标签: qtideqt-creator

解决方案


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


推荐阅读