-
Notifications
You must be signed in to change notification settings - Fork 22
Setup Qt Creator for ROS
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
Goto this link and follow the instruction.
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.
- First uninstall Qt Creator if it has been installed from apt-get
sudo apt-get remove --purge qtcreator
- Change directory to you home directory:
cd /home/username
- 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
- Make .run file an executable:
chmod +x qt-creator-opensource-linux-x86_64-3.4.1.run
- Execute file:
./qt-creator-opensource-linux-x86_64-3.4.1.run
- Follow the instruction in the GUI
- Remove executable:
rm qt-creator-opensource-linux-x86_64-3.4.1.run
- Next create a desktop shortcut:
ln -s ~/.local/share/applications/QtProject-qtcreator.desktop ~/Desktop/QtCreator.desktop
- 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
- Open file:
sudo gedit /etc/rc.local
- Add this line before the exit 0 line:
echo 0 | tee /proc/sys/kernel/yama/ptrace_scope
- Reboot computer
If version 3.3.1 or higher was installed you are able to set the theme to dark following the steps bellow.
- Open Qt Creator
- Goto: Tools > Options > Environment > General
- There should be a setting for Theme in the "User Interface" group containing a drop down box with two options "default or dark".
- Open Qt Creator
- Goto: Tools > Options > Text Editor > Font & Colors
- There is a drop down box in the "Color Scheme" group where you select different syntax color schemes.
- Addition schemes can be added as explained the below links.
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.
- Open Qt Creator
- Goto: Tools > Options > Environment > MIME Types
- 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 |
- 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>
- Open Qt Creator
- Goto: Tools > Options > C++ > Code Style
- Select Import… and browse to the file downloaded in step 1. The Current Settings should say ROS.
- Goto: Tools > Options > Qt Quick > Code Style and repeat step 4.
- Also need to change indent size to 2 space: Tools > Options > Text Editor > Behavior
- Goto: File > New File or Project... > Import Existing Project > Choose...
- Enter a Project Name and Browse... to the ROS project workspace then select Next >
- If everything was setup correctly in section 1, all necessary folder and files should be selected for import.
- 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;
- Select Apply Filter
- Select Next >
- Select Finished
- If the "Project Browser" is not visible press: Alt+0
- First open the project, then navigate to the Projects > Build Settings
- Remove existing "Build Steps".
- 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}
- Remove existing "Clean Steps".
- Add a custom clean step Add Clean Step > Custom Process Step as shown below.
- Command: rm
- Arguments: -rf ./devel ./build
- Working directory: %{buildDir}
- First open the project, then navigate to the Projects > Run Settings
- Add a "Run Configuration" by selecting the Add > Custom Executable
- Next select the Browse... associated with the executable field and browse to the executable you wish to debug in the workspace devel directory.
- Now everything should be setup and ready to begin debugging.
- Open a terminal and start a roscore
- Open another terminal and browse to the catkin workspace and source directory.
- Next open qt creator from this terminal using the command below and open project.
- Command:
qtcreator &
- Command:
- Now from the terminal launch the project you wish to debug. (optional: if using launch file)
- Next in qt creator browse to the file you wish to debug and insert break points.
- 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.
- Now depending on where the break points were placed qt should be stopped at a break point.
- Open a terminal and browse to the catkin workspace and source directory.
- Next open qt creator from this terminal using the command below and open project.
- Command: $ qtcreator &
- Now from the terminal launch the project you wish to debug. (optional: if using launch file)
- Next in Qt Creator browse to the file you wish to debug and insert break points.
- Menu Bar > Debug > Start Debugging > Attach to Running Process
- Now select the Process ID and then click the button Attach to Process.
- 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.
- First clone this repository https://github.com/Levi-Armstrong/gdb-7.7.1.git
- Follow the instruction in the README file a. ./configure b. make c. make install
- Goto:Tools > Options > Debugger > GDB
- 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
- 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.
- 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
.
- Install Clang
sudo apt-get install clang-format-3.6
- Goto:Tools > Options > Environment > External Tools
- Select: Add > Add Tool
- 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
- Select Apply
- Now lets add a quick key.
- Goto:Tools > Options > Environment > Keyboard
- In the filter box type "Clang" and you should pull up the new tool.
- In the Shortcut section enter the Target text box and press ctrl + shift + k to set the shortcut.
- 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.