Setup Qt Creator for ROS

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

Set 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”.

Set 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 in the below links.
    1. https://github.com/welkineins/qtcreator-themes
    2. https://github.com/alexpana/qt-creator-wombat-theme

Set ROS Code Format

  1. Open Qt Creator
  2. On the sidebar: Projects > Editor
    • Changing it globally at Tools > Options > C++ or within Projects > Code Style does not work.

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 below.

    • 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.

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

    1. ./configure
    2. make
    3. sudo checkinstall
  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
    
  5. 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.

  6. 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.