Qt5.9.8 creater警告:the code model could not parse an included file

the code model could not parse an included file,which might lead to incorrect code completion and highlighting,for example

解决办法:帮助-->关于插件-->C++-->ClangCodeModel的勾去掉即可

注意,去掉之后一定要重启Qt Creator

出现的原因:

CreateMenu.h中定义如下:


 
 
  1. #ifndef CREATEMENU_H
  2. #define CREATEMENU_H
  3. #include <QMenuBar>
  4. #include "mainwindow.h"
  5. class MainWindow;
  6. class Menu : public QMenuBar
  7. {
  8. Q_OBJECT
  9. public:
  10. Menu(QWidget *parent,MainWindow *p);
  11. ~Menu();
  12. }
  13. #endif

mainwindow.h中定义如下:


 
 
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4. #include "CreateMenu.h"
  5. namespace Ui{
  6. class MainWindow;
  7. }
  8. class Menu;
  9. class MainWindow : public QMainWindow
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit MainWindow(QWidget *parent = nullptr);
  14. ~MainWindow();
  15. private:
  16. Menu i_MenuBar;
  17. }
  18. #endif

报这个错误的原因是因为重复包含头文件的原因,CreateMenu.h中包含了mainwindow.h头文件,但mainwindow.h头文件又包含了CreateMenu.h,所以才会导致这种报错的发生,按照上面的解决方案可以完美解决!

一定要注意在CreateMenu.h中使用MainWindow类时,在头文件开始一定要写上class MainWindow,这是对MainWindow类的声明,否则在使用MainWindow时会报错;同样在mainwindow.h头文件中使用Menu类时,在头文件开始一定要写上class Menu,这是对Menu类的声明,否则在使用Menu时会报错;

原文连接:https://blog.csdn.net/u014453443/article/details/91975453

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值