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
几天前我有一种预感(我完全忘记了我是如何得到这种预感的),这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 中的开头 {。
解决方案
Qt 论坛上有人告诉我转到帮助菜单 > 关于插件 > 禁用 ClangCodeModel 插件。这需要重新启动 Qt Creator,但它解决了我的问题。
推荐阅读
- gcp-load-balancer - 将多个通配符 TLS 证书与单个 GCE 负载均衡器一起使用
- linux - Rust 非交互式标准输入读取
- javascript - 减少 node_modules 后 node_modules 出错
- python - 记录一个mac地址并检查它是否有效
- python - 从偶数索引位置提取字符
- bash - 从第二个函数参数开始的 Ruby for 循环
- javascript - 将文件列表发布到 ajax 帖子中的控制器
- airflow - 气流:自定义 SubDagOperator 中的放大 Sub Dag 按钮
- optimization - CPLEX - 优化 - 按期间最小化生产成本:错误:模型是非凸的
- typescript - 如何在函数内使用泛型获取嵌套接口值?