【问题标题】:Cmake and QT5 - Include only takes one argumentCmake 和 QT5 - Include 只需要一个参数
【发布时间】:2015-01-31 14:51:28
【问题描述】:

来自这个话题: Ubuntu CMake what path to add to CMAKE_MODULE_PATH

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

按照上述主题的指南,我现在有一个 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 后出现以下错误:

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

所以这告诉我变量 QT_USE_FILE 现在是一个列表,而以前不是。不知道这是否正确,也不知道我能做什么。

谢谢 一月

【问题讨论】:

    标签: c++ qt cmake


    【解决方案1】:
    CMake Error at CMakeLists.txt:36 (INCLUDE):
    include called with wrong number of arguments.  Include only takes one
    file.
    

    表示变量QT_USE_FILE为空。

    在带有 Qt5 的 CMake 中,您应该使用宏 qt5_use_modules 而不是 QT_USE_FILEQT_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)

    UPD
    目前不推荐使用qt5_use_modules,而应使用target_link_libraries simpleTree Qt5::Widgets(另请参阅this answer)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-29
      • 2021-12-10
      • 1970-01-01
      • 2018-10-21
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多