Write and Debug code for ROS with QtCreator

To write code for ROS you can use a simple text editor like “gedit”, “vi” or “nano”, but when the project becomes complex you risk to lose yourself without autocompletition, indexing and project trees. On the other hand one of the must difficult thing is to debug different rosnodes using textual GDB.

Using a graphical IDE (Integrated Development Environment) like QtCreator can speed up the process of code writing and the debug phase… and its configuration is really simple since it fully support CMake!

QtCreator is a free and popular IDE. Originally designed to create Qt applications, it is also very useful to edit C++ code in general.
Eclipse is another popular IDE but QtCreator works better with ROS… and I love Qt 😉

Installing QtCreator

In order to be able to work with ROS code, QtCreator needs to be able to source the environment (your .bashrc). You can either launch it from a terminal, or create a custom qtcreator.desktop file:

First copy the standard qtcreator.desktop file:

Then edit it and change the Exec line into:

Finally, remove the QtCreator icon from the launcher (if present) by right clicking it and selecting “Unlock from launcher“; drag and drop the qtcreator.desktop file you just created to the launcher.

Configuring QtCreator

QtCreator offers lots of options. The most important one is to configure the code style to indent using 2 spaces.

  1. Open “Tools > Options …
  2. Under “C++ > Code Style“, copy the GNU style (name the copy driving for instance), and edit it
  3. Set the tab and indent size to 2 (spaces only)

Opening a ROS project

  1. Click “File > Open file or projet” and browse to the CMakeLists.txt at the root of your catkin source space (e.g. ~/catkin_ws/src/CMakeListst.txt).
  2. Set the build location to the build space of the catking workspace (~/catkin_ws/build).
  3. run cmake with no arguments

It should start parsing the packages in the project (as with catkin_make) and the list of packages should appear in the project view.

It is also possible to open a single package, just search for the relative CMakeFile.txt (e.g. ~/catkin_ws/src/Robocontroller-ROS/CMakeListst.txt) and set the right build folder (e.g. ~/catkin_ws/src/Robocontroller-ROS/build)

You are now ready to work with QtCreator and ROS. You can run your ROS nodes inside QtCreator and you can debug them.

Very important: don’t forget to add

to the CMakeLists.txt of your packages to add debug information to your executables to let QtCreator (and any other debug tool) to be able to debug your code.

Note: empty error dialog box

If you cannot debug your application and you get an empty error dialog box you must set the correct node file to QtCreator:

  • click “Project” on the left
  • choose “Run” tab
  • add a new “Run configuration” and select the correct executable of your node that it is contained in the “lib” folder under the “build” folder (i.e.[build_path]/devel/lib/[package_name]/[node_name])

Remember that the nodes compiled with QtCreator are not available in the ROS environment, so after your debug you must go back to your workspace main directory and run the “catkin_make” command to compile the packages in your ROS workspace.

source: http://wiki.ros.org/IDEs#QtCreator
source: https://github.com/StanfordDrivingTeam/driving_public/wiki/Setting-up-QtCreator


  1. Hey !
    I need your help for using Qt.
    Either Qt or eclipse doesn’t work with my laptop.

    For Qt, I followed the tutorial but each time I end up, in QT, with all the package from /opt/ros/indigo (so lots of files) and never with my own package in ~/catkin_ws

    I really don’t understand why.

    Thank you =)

    • It is ok.
      If you want to open a single package, just follow the same procedure, but select the CMakeLists.txt as indicated starting by “It is also possible to open a single package, just search for the relative CMakeFile.txt…”

  2. When I open QtCreator I get two errors one which states I do not have permission to create file /opt/ros/indigo/share/catkin/cmake/toplevel.cmake.user: Permission Denied. I also says there are no valid kits found and the project cmake is not yet configured. Qt Creator uses the invalid kit desktop to parse the project.

    • Sorry, forgot to ask a question. Have you experienced this? or know how to fix it?

      • Try to open a single package instead of the whole “catkin_ws”

      • I have the same problem, since I can follow this tutorial successfully with Ubuntu12.04/ Qt Creator 2.4.1, but not for Ubuntu 14.04 and Qt Creator 3.0.
        So, From the official ROS http://wiki.ros.org/IDEs#QtCreator,

        “Recently this has started to fail, because the main CMakeLists is a symlink to a non writtable location. The workaround is to make a copy to toplevel.cmake instead of using a symlink. And if you want the project to be named something else than “Project” then add a line at the top with “project(MyProjectName)”.

        So I fixed the problem by:
        $ cd /src
        $ rm CMakeLists.txt
        $ cp /opt/ros/indigo/share/catkin/cmake/toplevel.cmake CMakeLists.txt

        Then, open QT, and follow the tutorial. Hope this helps.

  3. Is there some sort of set of example/sample code that is not the catkin_ws that I can open and sort through as I am not familiar with this platform.

    • You should install the whole Qt framework and you will get also the examples. But ROS does not use Qt… I am a Qt lover, so I like to use QtCreator to write code for ROS and debug it, but you can use the IDE that you like more ?

  4. How would I go about installing the whole QT framework? Is there a guide/link?

  5. So I have QT Creator on the jetson, where is the sample code located? Also is there a native IDE for ROS that can be used on the Jetson?

  6. Hi, I have one question.
    Release mode is executed normally.
    Debug mode also runs normally.
    However, if you click on start Debug, no executable specified. Debugging has finished. Why is this happening?

    • It is a problem with CMakeFiles.txt and QtCreator. You must go to Projects->Run, press Add and specify manually which is the correct executable to be debugged

Leave a Comment