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中定义如下:
-
#ifndef CREATEMENU_H
-
#define CREATEMENU_H
-
-
#include <QMenuBar>
-
#include "mainwindow.h"
-
-
class MainWindow;
-
class Menu :
public QMenuBar
-
{
-
Q_OBJECT
-
public:
-
Menu(QWidget *parent,MainWindow *p);
-
~Menu();
-
}
-
-
#endif
mainwindow.h中定义如下:
-
#ifndef MAINWINDOW_H
-
#define MAINWINDOW_H
-
-
#include <QMainWindow>
-
#include "CreateMenu.h"
-
-
namespace Ui{
-
class MainWindow;
-
}
-
-
class Menu;
-
-
class MainWindow :
public QMainWindow
-
{
-
Q_OBJECT
-
public:
-
explicit MainWindow(QWidget *parent = nullptr);
-
~MainWindow();
-
private:
-
Menu i_MenuBar;
-
}
-
-
#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