Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Qt CMake项目中找不到QCursor_C++_Qt_Cmake_Qt5_Qcursor - Fatal编程技术网

C++ 在Qt CMake项目中找不到QCursor

C++ 在Qt CMake项目中找不到QCursor,c++,qt,cmake,qt5,qcursor,C++,Qt,Cmake,Qt5,Qcursor,我正在尝试用Qt在Linux上构建一个应用程序,在这里我可以设置光标的位置。该项目由CMake管理 CMakeLists.txt: cmake_minimum_required(VERSION 2.8.4) project(Project) add_definitions(-std=gnu++14 -std=c++14 -Wall -Wextra) set(CMAKE_PREFIX_PATH "/home/elmewo/Libraries/Qt/5.3/gcc_64") set(CMAKE_A

我正在尝试用Qt在Linux上构建一个应用程序,在这里我可以设置光标的位置。该项目由CMake管理

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.4)
project(Project)

add_definitions(-std=gnu++14 -std=c++14 -Wall -Wextra)
set(CMAKE_PREFIX_PATH "/home/elmewo/Libraries/Qt/5.3/gcc_64")
set(CMAKE_AUTOMOC ON)

find_package(Qt5Core REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Gui REQUIRED)

include_directories(${CMAKE_SOURCE_DIR}/src)

set(SOURCE_FILES src/main.cpp)

add_executable(Project ${SOURCE_FILES})

qt5_use_modules(Project Core Quick Gui)
这些包由CMake找到。但是当我试着

#include <QCursor>
我能够在同一台机器上编译另一个基本的QGUI应用程序

QCursor文件位于${CMAKE_PREFIX_PATH}/include/QtGui中


我遗漏了什么吗?

您似乎依赖于2.8.4,因此至少需要更改生成规则,或者需要将依赖项升级到至少cmake 2.8.9版:

将Qt 5与2.8.9以上的CMake一起使用

如果使用早于2.8.9的CMake,则qt5_use_modules宏不可用。尝试使用它将导致错误

要将Qt 5与2.8.9之前的CMake版本一起使用,必须使用目标链接库、包含目录和添加定义命令,并使用qt5生成moc或qt5包裹cpp手动指定moc要求:

因此,如果您坚持使用旧的cmake,请添加以下内容:

# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Quick_INCLUDE_DIRS})

#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(helloworld Qt5::Core Qt5::Gui Qt5::Quick)

另外,将其核心化是一个坏主意:
set(CMAKE\u PREFIX\u PATH)/home/elmewo/Libraries/Qt/5.3/gcc\u 64”)
。请尝试通过
-D
将其传递给cmake。谢谢。我已经在使用CMake 2.8.12。无论如何,按照Qt主页上更新的CMake手册,不需要手动包含头文件,因为它是在将库链接到目标时自动完成的。我现在找到了头文件。再次感谢你
# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Quick_INCLUDE_DIRS})

#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(helloworld Qt5::Core Qt5::Gui Qt5::Quick)