[QT][?] Found unsuitable Qt version "5.0.2" from /usr/bin/qmake, this code requires Qt 4.x

1. 调试 错误: Found unsuitable Qt version "5.0.2" from /usr/bin/qmake, this code requires   Qt 4.x

CMake Error at /usr/share/cmake-2.8/Modules/FindQt4.cmake:1193 (MESSAGE):

Found unsuitable Qt version "5.0.2" from /usr/bin/qmake, this code requires Qt 4.x

Call Stack (most recent call first): ros_tutorials-hydro-devel/turtlesim/CMakeLists.txt:6 (find_package)


   执行下面的命令 : sudo apt-get install qt4-default

The following packages will be REMOVED:
  qt5-default
The following NEW packages will be installed:
  qt4-default

sudo apt-get install qt5-default

2.   usr/bin/ld: cannot open output file test: Is a directory

  提示错误

/usr/bin/ld: cannot open output file test: Is a directory
collect2: ld returned 1 exit status

 文件夹同名问题。

SET(main_src_SOURCES ${treebot_SOURCE_DIR}/main_src/mainwindow.cpp
                 ${treebot_SOURCE_DIR}/main_src/serialport.cpp
                 ${treebot_SOURCE_DIR}/main_src/util.cpp
                 ${treebot_SOURCE_DIR}/main_src/slidervelocity.cpp
  )

SET(main_src_HEADERS ${treebot_SOURCE_DIR}/main_src/mainwindow.h
                 ${treebot_SOURCE_DIR}/main_src/serialport.h
                 ${treebot_SOURCE_DIR}/main_src/treerobotconstant.h
                 ${treebot_SOURCE_DIR}/main_src/slidervelocity.h
                 ${treebot_SOURCE_DIR}/main_src/util.h
)

QT5_WRAP_CPP(main_src_HEADERS_MOC ${main_src_HEADERS})
    QT5_WRAP_CPP  时会在编译路径build下生成main_src 文件夹存放相应的cmake缓存。

而我又有这样的执行文件需生成 main_src  ;    造成同名使得无法生成执行文件main_src.

  
add_executable(main_src   ${treebot_SOURCE_DIR}/main_src/main.cpp
                       # ${treebot_SOURCE_DIR}/qrslam/CameraEstimation.cpp
                       # ${treebot_SOURCE_DIR}/qrslam/CameraEstimation.h
                        ${main_src_SOURCES}  ${main_src_HEADERS_MOC}   ${main_src_HEADERS}  ${main_src_UI_HEADERS}
 )

TARGET_LINK_LIBRARIES(main_src ${Qt5Core_LIBRARIES}  ${Qt5Widgets_LIBRARIES}  ${Qt5Gui_LIBRARIES}  ${Qt5SerialPort_LIBRARIES}
                      CameraEstimation
 )

解决方法:

1).设置编译路径路径;

设置输出文件路径:  执行文件则生成在/bin内

   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
   set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

2). 改生成执行文件命名。

add_executable(treebot   ${treebot_SOURCE_DIR}/main_src/main.cpp
                       # ${treebot_SOURCE_DIR}/qrslam/CameraEstimation.cpp
                       # ${treebot_SOURCE_DIR}/qrslam/CameraEstimation.h
                        ${main_src_SOURCES}  ${main_src_HEADERS_MOC}   ${main_src_HEADERS}  ${main_src_UI_HEADERS}
 )

TARGET_LINK_LIBRARIES(treebot ${Qt5Core_LIBRARIES}  ${Qt5Widgets_LIBRARIES}  ${Qt5Gui_LIBRARIES}  ${Qt5SerialPort_LIBRARIES}
                      CameraEstimation
 )

3. qt5_wrap_ui生成的头文件 ui_mainwindow.h  中#include "slidervelocity.h"文件出错。

#CMakeLists.txt中 
 qt5_wrap_ui(main_src_UI_HEADERS ${treebot_SOURCE_DIR}/main_src/mainwindow.ui)

<span style="color:#be1414;">//ui_mainwindow.h</span>中
#include <QtWidgets/QToolBar>
#include <QtWidgets/QWidget>
#include "slidervelocity.h"

问题原因:主要是cmake生成的路径在build,即 qt5_wrap_ui  命令生成的文件 ui_mainwindow.h 在build中,而 slidervelocity.h  在main_src 文件夹下。

解决方法:

1)  直接改ui_mainwindow.h 的include说明

#include "../main_src/slidervelocity.h"
这种方式比较愚笨,而是想直接通过cmakelists的形式完成。

2) 在cmakelists中加入包含文件路径

include_directories(${treebot_SOURCE_DIR}/main_src)

则在<span style="color:#be1414;">ui_mainwindow.h</span>就可以识别下面包含文件
#include "slidervelocity.h"

3)  改变   qt5_wrap_ui生成文件的路径,让其生成的slidervelocity.h   ui_mainwindow.h  文件位置到  main_src ,与 slidervelocity.h在同一文件夹。



你可能感兴趣的:([QT][?] Found unsuitable Qt version "5.0.2" from /usr/bin/qmake, this code requires Qt 4.x)