Using Axii (Recommended)
Axii provides modules for different versions of QtCreator. These modules configure QtCreator correctly to work well with ArmarX workspaces.
- Note
- For tools such as IDEs, it is recommended to create a separate ArmarX workspace. See Axii's documentation (Tools Integration) for instructions.
To install QtCreator, add the respective module and run an upgrade:
On Ubuntu 18:
axii workspace add tools/qtcreator/5.0
axii workspace upgrade -m tools/qtcreator/5.0
On Ubuntu 22:
axii workspace add tools/qtcreator/10.0
axii workspace upgrade -m tools/qtcreator/10.0
Using the Official Installer
- Note
- Using flatpak to install QtCreator is not recommended. The flatpak installation of QtCreator may not optimally use / interact with the system environment. If in doubt, install via the official installer (see instructions below).
Install QtCreator
- Download the Qt Online Installer from here. The downloaded file should be called
qt-creator-opensource-linux-x86_64-5.0.3.run.
- Move the installer to a suitable directory, e.g.
~/opt/qtcreator/
$ mkdir -p ~/opt/qtcreator
$ cd ~/opt/qtcreator
$ mv ~/Downloads/qt-creator-opensource-linux-x86_64-5.0.3.run .
$ chmod u+x qt-creator-opensource-linux-x86_64-5.0.3.run
$ ./qt-creator-opensource-linux-x86_64-5.0.3.run
- In the installer, you first have to enter some account credentials. If you don't want to create an account, ask your supervisor. Then, press Next.
- Read the license obligations, then check the two boxes "I have read and approve the obligations of using Open Source Qt" and "I am an individual person not using Qt for any company. Then, press <em>Next</em>.
- In the next screen, you will be told that there is no commercial license available in your Qt account. This is okay, you can continue with the Qt Open-Source installation. Press <em>Next</em>.
- Specify the installation directory, e.g. <tt>~/opt/qtcreator/qtcreator</tt>, then press <em>Next</em>.
- Next, you can choose which components to install. There should only be the "Developer and Designer Tools", which are already selected. Press <em>Next</em>.
- Again, read and accept the agreement, then press <em>Next</em>.
- Finally, press <em>Install</em>.
- Wait until installation is complete.
To map the command <tt>qtcreator</tt> to the new version, add this line to your <tt>~/.bashrc</tt>:
@icode{shell}
export PATH="$HOME/opt/qtcreator/qtcreator/bin:$PATH"
@endicode
Source your <tt>~/.bashrc</tt> (<tt>source ~/.bashrc</tt>) or open a new terminal, then confirm that the new version is used:
@icode{shell}
$ which qtcreator
/.../opt/qtcreator/qtcreator/bin/qtcreator
$ qtcreator -version
Qt Creator 5.0.3 based on Qt 5.15.2
[...]
@endicode
Start QtCreator
@icode{shell}
qtcreator
@endicode
and proceed by configuring like explained below.
@subsection autotoc_md36 Configure QtCreator
You should edit some settings so they fit to our working setup and conventions.
Open the Settings via <strong>Tools</strong> > <strong>Options ...</strong> .
* In the <strong>Kits</strong> section:
* In the <strong>CMake</strong> tab:
* <strong>Clone</strong> the <em>System CMake at ...</em>
* Select the new entry, rename it to "ArmarX CMake", and press <strong>Make Default</strong>
* Uncheck <strong>Autorun CMake</strong>
* Set the path to the correct CMake installation
* If you use <a href="https://git.h2t.iar.kit.edu/sw/armarx/meta/axii" >Axii</a>, set the path to <tt>\$ARMARX_WORKSPACE/deps/cmake-3.21/cmake-3.21.3-linux-x86_64/bin/cmake</tt> and help file to <tt>\$ARMARX_WORKSPACE/deps/cmake-3.21/cmake-3.21.3-linux-x86_64/doc/cmake/CMake.qch</tt>.
* If you installed QtCreator via <strong>Flatpak</strong>, prepend the path by <tt>/run/host/</tt> (e.g. <tt>/run/host/usr/bin/cmake</tt>)
* If you [installed an up-to-date CMake without sudo](Update-CMake-(non-sudo)), set the path to <tt>.../cmake/bin/cmake</tt> and help file to <tt>.../cmake/doc/cmake/CMake.qch</tt>.
* In the <strong>Kits</strong> tab:
* <strong>Clone</strong> the Qt5 Kit
* Select the new entry, rename it to "ArmarX" and press <strong>Make Default</strong>
* Scroll down and set the <strong>CMake Tool</strong> to the newly created "ArmarX CMake"
* Make sure a <strong>CMake Generator</strong> is configured. If not, press <strong>Change ...</strong>, select "Unix Makefiles" or "Ninja" as Generator, and press OK.
* In the <strong>Text editor</strong> section:
* In the <strong>Behavior</strong> tab:
* Under <em>Tabs And Indentation</em>, set select <strong>Spaces Only</strong> and set <strong>Tab Size</strong> to 4
* Under <em>Mouse and Keyboard</em>, uncheck <strong>Enable mouse navigation</strong> (having it enabled might interfere with Ctrl+C/Ctrl+V)
* In the <strong>Display</strong> tab:
* Check <strong>Display right margin at column</strong> and set the margin to <strong>100</strong>
* In the <strong>C++</strong> section:
* In the <strong>File Naming</strong> tab:
* Check <strong>Use "pragma once" instead of "#ifndef" guards</strong>
* Uncheck <strong>Lower case file names</strong>
* In the <strong>Build & Run</strong> section:
* In the <strong>General</strong> tab:
* Check <strong>Save all files before build</strong>
* In the <strong>Default Build Properties</strong> tab:
* Set the <strong>Default build directory</strong> to <tt>build</tt>
@section autotoc_md37 Optional: Enable Autoformatting via Clang Format
Autoformatting in QtCreator via clang format requires three things:
- An installation of <tt>clang</tt>
- The Beautifier plugin in QtCreator
- Clang format configuration files called <tt>.clang-format</tt> in the project directory or above
Clang format uses the <tt>.clang-format</tt> file in the project directory,
or the closest <tt>.clang-format</tt> in the closest parent directory of the project.
If no <tt>.clang-format</tt> exists in the project directory or any of its parent directories,
no autoformatting will happen.
@subsection autotoc_md38 H²T-suggested Code Style Using Axii
The Axii module <tt>h2t/code_style</tt> contains and distributes different <tt>.clang-format</tt> files in the workspace.
This module is added by default to every new workspace by Axii.
Alternatively, you can add it to your workspace using <tt>axii add h2t/code_style</tt>.
@subsection autotoc_md39 Clang and Beautifier Plugin via Axii
When using the <tt>tools/qtcreator/...</tt> modules,
<tt>clang</tt> and the Beautifier plugin for QtCreator are installed and configured
automatically by Axii.
@subsection autotoc_md40 Clang and Beautifier Plugin: Manual Setup
@subsubsection autotoc_md41 Install clang-14
Check whether <tt>clang-14</tt> is installed:
@icode{shell}
dpkg -V clang-14
@endicode
If this prints nothing, <tt>clang-14</tt> is installed.
Otherwise, it will say ‘dpkg: package 'clang-14’ is not installed`.
@subsubsection autotoc_md42 Recommended: Install via axii
If <tt>clang-14</tt> is <strong>not</strong> installed, install it by running (requires sudo):
@icode
axii workspace add tools/clang+llvm/14.0
axii workspace upgrade -m tools/clang+llvm/14.0
@endicode
@subsubsection autotoc_md43 Deprecated: Manuall installation
For reference, it is also possible to do an installation without axii.
@icode{shell}
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-14 main' | sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null
sudo apt update
sudo apt install -y clang-14 clang-format-14 clang-tidy-14 lldb-14 lld-14 clangd-14
@endicode
@subsubsection autotoc_md44 Add the Beautifier Plugin to QtCreator
Enable the **_Beautifier_** Plugin in QtCreator:
* In QtCreator, go to the Plugins menu via <strong>Help</strong> > <strong>About Plugins...</strong> .
* Find <strong>Beautifier</strong> (under <em>C++</em>) and enable the plugin by ticking the check box.
* Restart QtCreator.
In the settings of QtCreator (<strong>Tools</strong> > <strong>Options...</strong>), find the <strong>Beautifier</strong> section. There:
* In the <strong>Clang Format</strong> tab, under <em>Options</em>:
* If the <strong>Clang Format command</strong> is red, you might need to change it to <strong>clang-format-14</strong> or supply a full path to the executable
* Set <strong>Use predefined style</strong> to "File"
* Set <strong>Fallback style</strong> to "None"
* In the <strong>General</strong> tab:
* (Optional) Check <strong>Enable auto format on file save</strong> and set <strong>Tool</strong> to "ClangFormat"
* (Optional) Add a key shortcut to manually trigger the formatting when you see fit:
* In the <strong>Environment</strong> section, go to the <strong>Keyboard</strong> tab.
* Find and select the command "FormatFile" (without a space) under "ClangFormat".
* Add a keybinding such as <tt>Alt+I</tt>.
* You can also bind other commands, such as "DisableFormattingSelectedText", e.g. to
Alt+Shift+I
Run Clang Format Manually from the Command Line
To manually clang-format all C++ files in a package or directory, you can do something like this:
for file in source/**/*.{h,cpp}; do
clang-format-14 $file -i
; done