CMake找不到QXmlSimpleReader

时间:2016-07-22 17:31:04

标签: c++ qt cmake qt5

我有一个C ++头文件,其中包含以下行:

#include <QXmlSimpleReader>
#include <QXmlDefaultHandler>

我的cmake有以下几行:

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)

运行CMake时,我收到以下错误消息:

QXmlSimpleReader: No such file or directory
 #include <QXmlSimpleReader>

我做错了什么?

2 个答案:

答案 0 :(得分:1)

我猜你忘了链接Qt5xml。来自documentation的cmake 2.8.11及更高版本的工作示例,已修改为链接Qt5Xml:

cmake_minimum_required(VERSION 2.8.11)

project(testproject)

# 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 QtWidgets library
find_package(Qt5Xml)

# Tell CMake to create the helloworld executable
add_executable(helloworld WIN32 main.cpp)

# Use the Widgets module from Qt 5.
target_link_libraries(helloworld Qt5::Xml)

答案 1 :(得分:1)

由于某种原因,它不会添加到项目包括dirs。

将此一个添加到您的cmake

INCLUDE_DIRECTORIES( ${Qt5Xml_INCLUDE_DIRS} )