1.安装依赖
ghy@ghy-virtual-machine:~$ sudo apt-get install ros_melodic_qt-creat
ghy@ghy-virtual-machine:~$ sudo apt-get install ros-melodic-qt-create
2.创建qt功能包
(1)创建catkin_qt文件夹,并在catkin_qt目录下创建src文件夹
(可直接在主目录下右击新建文件夹创建)
(2)切换路径,创建qt功能包
ghy@ghy-virtual-machine:~$ cd catkin_qt/
ghy@ghy-virtual-machine:~/catkin_qt$ cd src/
ghy@ghy-virtual-machine:~/catkin_qt/src$ catkin_create_qt_pkg robot_control roscpp rviz
(3)查看是否安装
3.配置功能包
3.1打开catkin_qt/src/robot_control/,在打开的robot_control中打开CMakeLists.txt,修改以下四部分:
(1)设置包含当前目录
#add
set(CMAKE_INCLUDE_CURRENT_DIR ON)
(2)添加qt库
#add
find_package(Qt5 REQUIRED Core Widgets)
set(QT_LIBRARIES Qt5::Widgets)
(3)删除
(4)更改
3.2打开catkin_qt/src/robot_control/include/robot_control/,在打开的robot_control中打开main_window.hpp文件,修改以下内容
#include <QtWidgets/QMainWindow>
4.编译
返回上一级再编译
ghy@ghy-virtual-machine:~/catkin_qt/src$ cd ..
ghy@ghy-virtual-machine:~/catkin_qt$ catkin_make
5.运行
ghy@ghy-virtual-machine:~$ rosrun robot_control robot_control
出错理由:终端运行rosrun找不到对应的包
解决:在该终端下,输入
ghy@ghy-virtual-machine:~$ source /home/ghy/catkin_qt/devel/setup.bash
再运行rosrun,即可成功
ghy@ghy-virtual-machine:~$ rosrun robot_control robot_control