1

我正在尝试使用 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>

我的编译器说

fatal error: QCursor: file or directory not found

我能够在同一台机器上编译另一个基本的 QGuiApplication。

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

我错过了什么吗?

4

1 回答 1

1

似乎您依赖于 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 版本一起使用,必须使用 target_link_libraries、include_directories 和 add_definitions 命令,并使用 qt5_generate_moc 或 qt5_wrap_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)
于 2014-10-23T11:29:11.893 回答