背景
我目前正在使用 Eclipse Neon.3 并安装了“C/C++ CMake Build Support - Experimental”包(我没有使用 CMake 的 Eclipse 生成器)。我有一个使用成功构建的 Qt 5.8 的简单程序,但是,Eclipse 似乎无法索引 Qt 符号(例如 QCoreApplication、QDebug 等)。
这种情况的症状是:
- 没有代码完成建议
#include <QtCore>
和其他包含语句显示为未解决- Qt 符号,如
QCoreApplication
、QDebug()
和QCoreApplication.exec()
显示为未解析。
代码
CMakeLists.txt
文件
cmake_minimum_required(VERSION 3.5)
project(test-program)
set(CMAKE_CXX_STANDARD 11)
# Put the CMake files for Qt5 in the Prefix path.
set(Qt5_DIR /opt/Qt/5.8/gcc_64/lib/cmake/Qt5/)
#Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
#Find the Qt5Core Library
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)
set(SOURCE_FILES
src/main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} Qt5::Core)
main.cpp
(与 Eclipse 注释一起显示)
#include <QtCore> //Unresolved inclusion: <QtCore>
#include <QDebug> //Unresolved inclusion: <QDebug>
int main(int argc, char** argv){
QCoreApplication application(argc, argv);
//Type 'QCoreApplication' could not be resolved
qDebug() << "Test";
//Function 'qDebug' could not be resolved
application.exec();
//Method 'exec' could not be resolved
return 0;
}
问题
所以我的问题是:如何让 Eclipse 识别 Eclipse 识别 Qt 符号?或者这在这个时候是不可能的?