Cmake和QT5 - Include只有一个参数 [英] Cmake and QT5 - Include only takes one argument

查看:979
本文介绍了Cmake和QT5 - Include只有一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自此主题:
Ubuntu CMake要添加到CMAKE_MODULE_PATH的路径


我试图在我的项目中运行QT5,因为QT4不允许我包括QWebView。

I try to get QT5 in my project running, as QT4 does not allow me to include QWebView.

按照上述主题中的指南,我现在有一个CMakeList.txt:

Following the guides from the mentioned topics I now have a CMakeList.txt:

cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
project (simpleTree)
find_package(Qt5 REQUIRED COMPONENTS Widgets Core) 
find_package (VTK REQUIRED)
find_package (PCL 1.8.0 REQUIRED)

include_directories (${PCL_INCLUDE_DIRS})
link_directories (${PCL_LIBRARY_DIRS})
add_definitions (${PCL_DEFINITIONS})

set (project_SOURCES export/exportply.cpp export/writecsv.cpp main.cpp
         controller.cpp 
         gui/pclviewer.cpp
         import/importpcd.cpp 
         method/SphereFollowing.cpp 
         Model/crown.cpp 
         Model/Cylinder.cpp 
         Model/Segment.cpp 
         Model/Tree.cpp)
set (project_HEADERS controller.h 
         export/writecsv.h
         export/exportply.h
         gui/pclviewer.h
         import/importpcd.h 
         method/SphereFollowing.h 
         Model/crown.h 
         Model/Cylinder.h 
         Model/Segment.h 
         Model/Tree.h)
set (project_FORMS   gui/pclviewer.ui)
set (VTK_LIBRARIES vtkRendering vtkGraphics vtkHybrid QVTK)

QT5_WRAP_CPP (project_HEADERS_MOC   ${project_HEADERS})
QT5_WRAP_UI  (project_FORMS_HEADERS ${project_FORMS})

INCLUDE (${QT_USE_FILE})
ADD_DEFINITIONS (${QT_DEFINITIONS})
ADD_EXECUTABLE (simpleTree ${project_SOURCES}
               ${project_FORMS_HEADERS}
               ${project_HEADERS_MOC})

TARGET_LINK_LIBRARIES (simpleTree ${QT_LIBRARIES} ${PCL_LIBRARIES}       ${VTK_LIBRARIES})



我在将QT4线切换到QT5后收到以下错误: p>

I get the following error, after switching QT4 lines to QT5:

CMake Error at CMakeLists.txt:36 (INCLUDE):
include called with wrong number of arguments.  Include only takes one
file.

这告诉我,变量QT_USE_FILE现在是一个列表,不确定这是否正确,不确定我可以做什么。

So this tells me that the variable QT_USE_FILE is now a list, which it was not before. Not sure if this is right, and not sure what I can do.

感谢
Jan

Thanks Jan

推荐答案

CMake Error at CMakeLists.txt:36 (INCLUDE):
include called with wrong number of arguments.  Include only takes one
file.

这意味着变量 QT_USE_FILE 为空。

在CMake中使用Qt5,你应该使用 qt5_use_modules ,而不是 QT_USE_FILE QT_LIBRARIES

In CMake with Qt5 you should use macro qt5_use_modules instead of QT_USE_FILE and QT_LIBRARIES.

所以在你的 CMakeLists.txt 中你需要删除行:

INCLUDE($ {QT_USE_FILE} )

更改行:

TARGET_LINK_LIBRARIES(simpleTree $ {QT_LIBRARIES} $ {PCL_LIBRARIES} $ {VTK_LIBRARIES})



TARGET_LINK_LIBRARIES(simpleTree $ {PCL_LIBRARIES} $ {VTK_LIBRARIES})

并添加行:

qt5_use_modules(simpleTree Widgets)

So in your CMakeLists.txt you need to remove line:
INCLUDE (${QT_USE_FILE})
change line:
TARGET_LINK_LIBRARIES (simpleTree ${QT_LIBRARIES} ${PCL_LIBRARIES} ${VTK_LIBRARIES})
on the:
TARGET_LINK_LIBRARIES (simpleTree ${PCL_LIBRARIES} ${VTK_LIBRARIES})
and add line:
qt5_use_modules (simpleTree Widgets)

UPD

现在使用 qt5_use_modules 已弃用, target_link_libraries simpleTree Qt5 :: Widgets (请参阅此答案)。

UPD:
For now using qt5_use_modules is deprecated and target_link_libraries simpleTree Qt5::Widgets should be used instead (see also this answer).

这篇关于Cmake和QT5 - Include只有一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆