简体   繁体   中英

Cannot find QCursor in Qt CMake Project

I'm trying to build an application on Linux with Qt where I can set the Cursor position. The project is managed with 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)

The packages are found by CMake. But when I try to

#include <QCursor>

my compiler says

fatal error: QCursor: file or directory not found

I was able to compile another basic QGuiApplication on the same machine.

The QCursor file is situated in ${CMAKE_PREFIX_PATH}/include/QtGui.

Am I missing something?

It seems that you are depending on 2.8.4, so at least you either need to change your build rules based on this or you will need to upgrade the dependency to at least cmake version 2.8.9:

Using Qt 5 with CMake older than 2.8.9

If using CMake older than 2.8.9, the qt5_use_modules macro is not available. Attempting to use it will result in an error.

To use Qt 5 with versions of CMake older than 2.8.9, it is necessary to use the target_link_libraries, include_directories, and add_definitions commands, and to manually specify moc requirements with either qt5_generate_moc or qt5_wrap_cpp:

Therefore, please add these if you stick with old 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM