[Documentation] [TitleIndex] [WordIndex

Note: This tutorial assumes that you have completed the previous tutorials: Mingw Build Environment, Mingw Packages.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Mingw Qt-Ros Packages

Description: How to create qt-ros packages that can also be compiled by the mingw_cross compiler.

Tutorial Level: INTERMEDIATE

New in electric

  Show EOL distros: 

Not available

Not available.

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

The qt_ros stack provides a handy helper to set up a template that works much like the roscreate-pkg script.

rosrun qt_create roscreate-qt-pkg qfoo

Compiling

Package qfoo should be immediately compilable in rosbuild1 (native) and via rosbuild2 (mingw).

Native Linux Binaries

You can do the usual (rosbuild1) rosmake to generate a native linux qt app.

> . ~/mingwros/src/setup.bash
> rosmake qfoo

Mingw Binaries

Use the mingw build environment to rosbuild2 your mingw app. To be consistent with previous tutorials we assume your source tree is in ~/mingwros/src and parallel build tree is in ~/mingwros/build:

> . ~/mingwros/src/setup.bash
> mkdir ~/mingwros/build # note: your parallel build tree can actually be anywhere
> cd ~/mingwros/build
> cmake ~/mingwros/src
> cd qfoo
> make -j5            # -jx for number of parallel jobs

Finally copy the resulting rosbuild2 .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 make sure you add them to the rosbuild2 element as well.

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

Old Releases

The experimental diamondback release is no longer supported. The old instructions can be found here.

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


2020-01-25 12:51