QT-找開工程后,最上方提示the code model could not parse an included file, which might lead to incorrect code completion and highlighting, for example.


相關資料:

https://blog.csdn.net/u014453443/article/details/91975453

 

問題情況:

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  
 4 #include <QMenuBar>
 5 #include "mainwindow.h"
 6  
 7 class MainWindow;
 8 class Menu : public QMenuBar
 9 {
10     Q_OBJECT
11 public:
12     Menu(QWidget *parent,MainWindow *p);
13     ~Menu();
14 }
15  
16 #endif

mainwindow.h中定義如下:

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

報這個錯誤的原因是因為重復包含頭文件的原因,CreateMenu.h中包含了mainwindow.h頭文件,但mainwindow.h頭文件又包含了CreateMenu.h,所以才會導致這種報錯的發生,按照上面的解決方案可以完美解決!

一定要注意在CreateMenu.h中使用MainWindow類時,在頭文件開始一定要寫上class MainWindow,這是對MainWindow類的聲明,否則在使用MainWindow時會報錯;同樣在mainwindow.h頭文件中使用Menu類時,在頭文件開始一定要寫上class Menu,這是對Menu類的聲明,否則在使用Menu時會報錯;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM