[Documentation] [TitleIndex] [WordIndex

Goal

Set up a single ros package that can compile both native linux and mingw qt applications from the one source base.

Installation

Make sure you have followed the instructions in the previous tutorial for setting up a Mingw Build Environment that also includes qt_ros.

Design Considerations

Typically you'll be wanting to simply create a monitoring/debugging package with dependencies that rely only on roscpp and the various comms (msg/srv packages - either official ros packages or your own.

This separation of code from comms is quite important when it comes to creating mingw applications as you typically do not need the code (which may not be ported to mingw) for a dependant package, simply its comms. When designing your own packages, keep this in mind - keep code packages and comms packages separate!

QuickStart

Download the roscreate module from PyPI. This provides handy wizard scripts to quickly generate a working qt program.

> sudo apt-get install python-pip python-rospkg
> sudo pip install --upgrade roscreate

Change to the location of the stack where you want your package to be created, and fire away (for this example, we'll add it to the qt_ros stack):

> cd ~/win/src/qt_ros
> roscreate-qt-pkg qfoo

Then ensure that your stack CMakeLists.txt calls your package, e.g. in qt_ros/CMakeLists.txt:

foreach(subdir
    qt_build
    qt_create
    qt_tutorials 
    qfoo # <----- This has been inserted
    )
  add_subdirectory(${subdir})
endforeach()

Compiling

Package qfoo should be immediately compilable as both a native and mingw cross compiled build.

Native Linux Binaries

> cd ~/win
> mkdir -p native
> cd native
> cmake -DCMAKE_INSTALL_PREFIX=~/ros/native ~/win/src
> cd qt_ros/qfoo
> make -j5 # set -jN to the number of cores + 1 to speed up compiles

Mingw Binaries

Use the mingw build environment. As before:

> cd ~/win
> mkdir -p mingw
> cd mingw
> cmake
    -DCMAKE_TOOLCHAIN_FILE=${MINGW_CMAKE_TOOLCHAIN_FILE} 
    -C ${MINGW_CMAKE_ROS_CONFIG_FILE} 
    -DCMAKE_INSTALL_PREFIX=~/ros/mingw ~/win/src
> cd qt_ros/qfoo
> make -j5 

Finally copy the resulting .exe's to windows and run.

Extending the App

The roscreate-qt-pkg script is recommended even if you don't eventually build a similar template as it will generally be less effort to modify this than to construct it all manually.

Adding Dependencies

Do this in the usual way in the manifest.xml, but also extend the call in CMakeLists.txt where

find_package(ROS REQUIRED COMPONENTS qt_build roscpp)

Adding Sources

If you ensure you add all headers in include/qfoo/*.hpp and sources in src/*.cpp, then the app will continue to build fine without any cmake changes.

User Interface

You can use designer to modify ui/main_window.ui. Changes can then be picked up and acted on via main_window.hpp and main_window.cpp.

More Details

For a more detailed explanation of the cmake api and its usage for qt, refer to qt_build.

Screenshots

These snapshots are from qt_ros' qt_tutorials package.

mingw_demo.png


2022-05-28 12:46