Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

Setup Qt Creator for ROS

agutenkunst edited this page Sep 12, 2017 · 2 revisions

Table of Contents

1.1 Install Dependencies"Important Don't Skip"
1.1.1 Install latest stable version of Qt Creator
1.1.2 Install latest version of Qt Creator
1.1.3 Setup Ubuntu to allow debugging/ptrace
1.2 Setting Theme's and Scheme's
1.2.1 Qt Creator Theme
1.2.2 Syntax Color Schemes
1.3 Add ROS File Types
1.4 Add ROS Code Format
1.5 Import ROS Workspace
1.6 Setup Build Settings for Catkin Workspace
1.7 Setup Run Settings for Catkin Workspace
1.8 Debug Catkin Workspace
1.8.1 Debug a single file
1.8.2 Attach to a running process (Default when working with ROS)
1.9 Preventing Qt Creator form stepping into Boost, Eigen, etc.
1.10 Setup Clang Formatting

1.1 Install Dependencies "Important Don't Skip"

1.1.1 Install latest stable version of Qt Creator

Goto this link and follow the instruction.

1.1.2 Install latest version of Qt Creator

If you would like to have a dark theme you will need version 3.3.1 or higher and the process bellow explains how to get the latest version to date. The same process should work for later versions.

  1. First uninstall Qt Creator if it has been installed from apt-get
    • sudo apt-get remove --purge qtcreator
  2. Change directory to you home directory:
    • cd /home/username
  3. Download executable:
    • wget http://download.qt.io/official_releases/qtcreator/3.4/3.4.1/qt-creator-opensource-linux-x86_64-3.4.1.run
  4. Make .run file an executable:
    • chmod +x qt-creator-opensource-linux-x86_64-3.4.1.run
  5. Execute file:
    • ./qt-creator-opensource-linux-x86_64-3.4.1.run
  6. Follow the instruction in the GUI
  7. Remove executable:
    • rm qt-creator-opensource-linux-x86_64-3.4.1.run
  8. Next create a desktop shortcut:
    • ln -s ~/.local/share/applications/QtProject-qtcreator.desktop ~/Desktop/QtCreator.desktop
  9. Now add it to your local bin directory so you can launch qtcreator from the command line:
    • sudo ln -s /home/username/qtcreator-3.4.1/bin/qtcreator /usr/local/bin/qtcreator

1.1.3 Setup Ubuntu to allow debugging/ptrace

  1. Open file:
    • sudo gedit /etc/rc.local
  2. Add this line before the exit 0 line:
    • echo 0 | tee /proc/sys/kernel/yama/ptrace_scope
  3. Reboot computer

1.2 Setting Theme's and Scheme's

1.2.1 Qt Creator Theme

If version 3.3.1 or higher was installed you are able to set the theme to dark following the steps bellow.

  1. Open Qt Creator
  2. Goto: Tools > Options > Environment > General
  3. There should be a setting for Theme in the "User Interface" group containing a drop down box with two options "default or dark".

1.2.2 Syntax Color Schemes

  1. Open Qt Creator
  2. Goto: Tools > Options > Text Editor > Font & Colors
  3. There is a drop down box in the "Color Scheme" group where you select different syntax color schemes.
  4. Addition schemes can be added as explained the below links.

1.3 Add ROS File Types

This allows Qt Creator to recognize file types like *.launch as xml for syntax highlighting and specifies that it needs to be included during the project import.

  1. Open Qt Creator
  2. Goto: Tools > Options > Environment > MIME Types
  3. The table below is a start to a list of extension to be added:
MIME Type Extensions
application/xml *.launch; *.xacro; *.urdf
text/plain *.srv; *.msg

1.4 Add ROS Code Format

  1. Download this xml file.
    • Note: File has not been uploaded yet so for now create an xml file named ROS.xml and copy the code below in to the file and save it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorCodeStyle>
<!-- Written by Qt Creator 2.4.1, 2014-11-18T11:09:25. -->
<QtCreator>
 <data>
  <variable>CodeStyleData</variable>
  <valuemap type="QVariantMap">
   <value type="bool" key="AlignAssignments">false</value>
   <value type="bool" key="AutoSpacesForTabs">false</value>
   <value type="bool" key="ExtraPaddingForConditionsIfConfusingAlign">true</value>
   <value type="bool" key="IndentAccessSpecifiers">false</value>
   <value type="bool" key="IndentBlockBody">true</value>
   <value type="bool" key="IndentBlockBraces">false</value>
   <value type="bool" key="IndentBlocksRelativeToSwitchLabels">false</value>
   <value type="bool" key="IndentClassBraces">false</value>
   <value type="bool" key="IndentControlFlowRelativeToSwitchLabels">true</value>
   <value type="bool" key="IndentDeclarationsRelativeToAccessSpecifiers">true</value>
   <value type="bool" key="IndentEnumBraces">false</value>
   <value type="bool" key="IndentFunctionBody">true</value>
   <value type="bool" key="IndentFunctionBraces">false</value>
   <value type="bool" key="IndentNamespaceBody">false</value>
   <value type="bool" key="IndentNamespaceBraces">false</value>
   <value type="int" key="IndentSize">2</value>
   <value type="bool" key="IndentStatementsRelativeToSwitchLabels">true</value>
   <value type="bool" key="IndentSwitchLabels">false</value>
   <value type="int" key="PaddingMode">2</value>
   <value type="bool" key="SpacesForTabs">true</value>
   <value type="int" key="TabSize">2</value>
  </valuemap>
 </data>
 <data>
  <variable>DisplayName</variable>
  <value type="QString">ROS</value>
 </data>
</QtCreator>
  1. Open Qt Creator
  2. Goto: Tools > Options > C++ > Code Style
  3. Select Import… and browse to the file downloaded in step 1. The Current Settings should say ROS.
  4. Goto: Tools > Options > Qt Quick > Code Style and repeat step 4.
  5. Also need to change indent size to 2 space: Tools > Options > Text Editor > Behavior

1.5 Import ROS Workspace

  1. Goto: File > New File or Project... > Import Existing Project > Choose...
  2. Enter a Project Name and Browse... to the ROS project workspace then select Next >
  3. If everything was setup correctly in section 1, all necessary folder and files should be selected for import.
  4. Add the list below to the "Show files matching:" textbox. Note: It is not a complete list.
    • *.c; *.cc; *.cpp; *.cp; *.cxx; *.c++; *.h; *.hh; *.hpp; *.hxx; *rst; *.launch; *.txt; *.xml; *.xacro; *.urdf; *.yaml; *.rviz; *.stl; *.STL; *.srv; *.msg; *.dae; *.srdf; *.py;
  5. Select Apply Filter
  6. Select Next >
  7. Select Finished
  8. If the "Project Browser" is not visible press: Alt+0

1.6 Setup Build Settings for Catkin Workspace

  1. First open the project, then navigate to the Projects > Build Settings
  2. Remove existing "Build Steps".
  3. Add a custom build step Add Build Step > Custom Process Step as shown below.
    • Command: catkin_make
    • Arguments: -DCMAKE_BUILD_TYPE=Debug
    • Working directory: %{buildDir}
  4. Remove existing "Clean Steps".
  5. Add a custom clean step Add Clean Step > Custom Process Step as shown below.
    • Command: rm
    • Arguments: -rf ./devel ./build
    • Working directory: %{buildDir}

1.7 Setup Run Settings for Catkin Workspace

  1. First open the project, then navigate to the Projects > Run Settings
  2. Add a "Run Configuration" by selecting the Add > Custom Executable
  3. Next select the Browse... associated with the executable field and browse to the executable you wish to debug in the workspace devel directory.
  4. Now everything should be setup and ready to begin debugging.

1.8 Debug Catkin Workspace

1.8.1 Debug a single file

  1. Open a terminal and start a roscore
  2. Open another terminal and browse to the catkin workspace and source directory.
  3. Next open qt creator from this terminal using the command below and open project.
    • Command: qtcreator &
  4. Now from the terminal launch the project you wish to debug. (optional: if using launch file)
  5. Next in qt creator browse to the file you wish to debug and insert break points.
  6. Now select the start debugger button.
    • Note: If using launch file it will kill the currently running executable generated from step 4 and start a new executable.
  7. Now depending on where the break points were placed qt should be stopped at a break point.

1.8.2 Attach to a running process (Default when working with ROS)

  1. Open a terminal and browse to the catkin workspace and source directory.
  2. Next open qt creator from this terminal using the command below and open project.
    • Command: $ qtcreator &
  3. Now from the terminal launch the project you wish to debug. (optional: if using launch file)
  4. Next in Qt Creator browse to the file you wish to debug and insert break points.
  5. Menu Bar > Debug > Start Debugging > Attach to Running Process
  6. Now select the Process ID and then click the button Attach to Process.
  7. Now depending on where the breakpoints were placed in qt, it should be stopped at a break point when it reaches one.
    • Note: Sometime it will be paused at a ros::spin, so check after it has attached and if it is passed and not at a inserted breakpoint click the continue button in the debugger.

1.9 Preventing Qt Creator form stepping into Boost, Eigen, etc.

  1. First clone this repository https://github.com/Levi-Armstrong/gdb-7.7.1.git
  2. Follow the instruction in the README file a. ./configure b. make c. make install
  3. Goto:Tools > Options > Debugger > GDB
  4. Add the following code below to the "Additional Startup Commands"
skip pending on
python
for root, dirs, files in os.walk("/usr/include/boost/"):
  for file in files:
    if file.endswith(".hpp"): 
      cmd = "skip file " + os.path.join(root, file)
      gdb.execute(cmd, True)

for root, dirs, files in os.walk("/usr/include/eigen3/Eigen/"):
  for file in files:
    if file.endswith(".hpp"): 
      cmd = "skip file " + os.path.join(root, file)
      gdb.execute(cmd, True)
end
skip enable
  1. Now when you are stepping through your code it should not step into Boost or Eigen. You can also add additional directories following the same process.
  2. Also if you would like to skip a particular function refer to the GDB documentation for instruction. It is something along the lines of skip function function_name.

1.10 Setup Clang Formatting

  1. Install Clang sudo apt-get install clang-format-3.6
  2. Goto:Tools > Options > Environment > External Tools
  3. Select: Add > Add Tool
  4. Fill in the information bellow.
    • Description: Clang Cpp Format
    • Executable: /usr/bin/clang-format-3.6
    • Arguments: -style="{Language: Cpp, AccessModifierOffset: -2, AlignAfterOpenBracket: true, AlignEscapedNewlinesLeft: false, AlignOperands: true, AlignTrailingComments: true, AllowAllParametersOfDeclarationOnNextLine: true, AllowShortBlocksOnASingleLine: false, AllowShortCaseLabelsOnASingleLine: false, AllowShortIfStatementsOnASingleLine: false, AllowShortLoopsOnASingleLine: false, AllowShortFunctionsOnASingleLine: All, AlwaysBreakAfterDefinitionReturnType: false, AlwaysBreakTemplateDeclarations: false, AlwaysBreakBeforeMultilineStrings: false, BreakBeforeBinaryOperators: None, BreakBeforeTernaryOperators: true, BreakConstructorInitializersBeforeComma: false, BinPackParameters: true, BinPackArguments: true, ColumnLimit: 80, ConstructorInitializerAllOnOneLineOrOnePerLine: false, ConstructorInitializerIndentWidth: 4, DerivePointerAlignment: false, ExperimentalAutoDetectBinPacking: false, IndentCaseLabels: false, IndentWrappedFunctionNames: false, IndentFunctionDeclarationAfterType: false, MaxEmptyLinesToKeep: 1, KeepEmptyLinesAtTheStartOfBlocks: true, NamespaceIndentation: None, ObjCBlockIndentWidth: 2, ObjCSpaceAfterProperty: false, ObjCSpaceBeforeProtocolList: true, PenaltyBreakBeforeFirstCallParameter: 19, PenaltyBreakComment: 300, PenaltyBreakString: 1000, PenaltyBreakFirstLessLess: 120, PenaltyExcessCharacter: 1000000, PenaltyReturnTypeOnItsOwnLine: 60, PointerAlignment: Left , SpacesBeforeTrailingComments: 1, Cpp11BracedListStyle: true, Standard: Cpp11, IndentWidth: 2, TabWidth: 8, UseTab: Never, BreakBeforeBraces: Allman, SpacesInParentheses: false, SpacesInSquareBrackets: false, SpacesInAngles: false, SpaceInEmptyParentheses: false, SpacesInCStyleCastParentheses: false, SpaceAfterCStyleCast: false, SpacesInContainerLiterals: true, SpaceBeforeAssignmentOperators: true, ContinuationIndentWidth: 4, CommentPragmas: '^ IWYU pragma:', ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ], SpaceBeforeParens: ControlStatements, DisableFormat: false}" -i %{CurrentDocument:FilePath}
    • Working directory: %{CurrentProject:Path}
    • Output: Show in Pane
    • Error output: Show in Pane
    • Environment: No Changes to apply.
    • Modifies current document: Checked
  5. Select Apply
  6. Now lets add a quick key.
  7. Goto:Tools > Options > Environment > Keyboard
  8. In the filter box type "Clang" and you should pull up the new tool.
  9. In the Shortcut section enter the Target text box and press ctrl + shift + k to set the shortcut.
  10. Now to apply the Clang format to a C++ file open the file in Qt Creator and press ctrl + shift + k and the file should be formatted correctly.