- Create a cmake Qt project.
- All qmake projects should be be ported to cmake first (CMake Port/Porting Guide).
- Create a ROS2 workspace (e.g. ros_qt_ws) folder with
ros_qt_ws/src/
subdirectory - Move the Qt project to
ros_qt_ws/src/
.
ros_qt_ws/
└── src
└── qt_demo
├── CMakeLists.txt
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
- Establish ROS2 package hierarchy:
- Move all the source files to a new directory:
ros_qt_ws/src/<Qt project>/src
- Move the header files to the
ros_qt_ws/src/<Qt project>/include/<Qt project>
- Currently the ROS2 workspace with the Qt project file tree should look similarly to this:
- Move all the source files to a new directory:
ros_qt_ws/
└── src
└── qt_demo
├── CMakeLists.txt
├── include
│ └── qt_demo
│ └── mainwindow.h
└── src
├── main.cpp
├── mainwindow.cpp
└── mainwindow.ui
-
Modify CMakeLists.txt file to comply with the ament_cmake guidelines. Example of such adjustment can be found in ros_qt_ws/src/qt_demo/CMakeLists.txt
- A generic ROS2 package can be found under test_pkg_ws/src/my_package. It has been generated as a quick reference using command:
ros2 pkg create --build-type ament_cmake --node-name my_node my_package
. - NOTE: it is important to pay attention to the difference between ament_target_dependencies() and target_link_libraries() as some libraries might need adjustments in calls (reference)
- A generic ROS2 package can be found under test_pkg_ws/src/my_package. It has been generated as a quick reference using command:
-
Create package.xml in
ros_qt_ws/src/<Qt project>/
ros_qt_ws/
└── src
└── qt_demo
├── CMakeLists.txt
├── include
│ └── qt_demo
│ └── mainwindow.h
├── package.xml
└── src
├── main.cpp
├── mainwindow.cpp
└── mainwindow.ui
To work with Qt creator it is best to:
- compile the package with
colcon build
from the terminal. - launch the Qt Creator application from within the terminal that has already sourced ROS2 environment.
- Ensure to delete any Qt Creator leftovers in the project, as they might make it impossible to load the package into Qt Creator (especially
*.user
files). - Open project by selecting package's
CMakeLists.txt
file. - Select
Import Existing Build...
option in Qt Creator and select the<workspace>/build/<package_name>
directory. - It should now possible to compile and run ROS2 package from within the Qt Creator IDE.
- NOTE: Sometimes it might be necessary to restart the setup running
colcon build
from CLI again.