sources/tech/20210630 9 reasons I love to use the Qt Creator IDE.md
8.4 KiB
9 reasons I love to use the Qt Creator IDE
Qt Creator is the glue between Qt's rich set of libraries and the programmer.
Qt Creator is the Qt framework's default integrated development environment (IDE) and hence the glue between Qt's rich set of libraries and the user. In addition to its basic features such as intelligent code completion, debugging, and project administration, Qt Creator offers a lot of nice features that make software development easier.
In this article, I will highlight some of my favorite Qt Creator features.
Dark mode
My first question when working with a new application is: Is there a dark mode? Qt Creator answers with: Which dark mode do you prefer?
You can activate dark mode in the Options menu. On the top menu bar, go to Tools, select Options, and go to the Environment section. Here is where you can select the general appearance:
(Stephan Avenwedde, CC BY-SA 4.0)
Custom appearance
Like every Qt application, Qt Creator's appearance is highly customizable with style sheets. Below, you can follow along with my approach to give Qt Creator a fancy look.
Create the file mycustomstylesheet.css
with the following content:
QMenuBar { background-color: olive }
QMenuBar::item { background-color: olive }
QMenu { background-color : beige; color : black }
QLabel { color: green }
Then start Qt Creator from the command line and pass the style sheet as a parameter with:
`qtcreator -stylesheet=mycustomstylesheet.css`
It should look like this:
(Stephan Avenwedde, CC BY-SA 4.0)
Read more about style sheets in the documentation.
Command-line parameters
Qt Creator accepts many command-line options. For example, if you want to automatically load your current project at startup, pass the path to the *.pro-file
:
`qtcreator ~/MyProject/MyQtProject.pro`
You can even pass the file and the line number that should be opened by default. This command opens the file main.cpp
at line 20:
`qtcreator ~/MyProject/main.cpp:20`
Read more about the Qt Creator-specific command-line options in the documentation.
Qt Creator is an ordinary Qt application, so, in addition to its own command-line arguments, it also accepts the generic arguments for QApplication and QGuiApplication.
Cross-compiling
Qt Creator allows you to define several toolchains, called Kits. A kit defines the binaries and SDK for building and running an application:
(Stephan Avenwedde, CC BY-SA 4.0)
This allows you to switch between completely different toolchains with just two clicks:
(Stephan Avenwedde, CC BY-SA 4.0)
Read more about kits in the manual.
Analyzer
Qt Creator integrates several of the most popular analyzers, such as:
- Linux Performance Analyzer (requires a special kernel)
- Valgrind memory profiler
- Clang-Tidy and Clazy, a linter for C/C++
(Stephan Avenwedde, CC BY-SA 4.0)
Debugger
When it comes to debugging, Qt Creator has a nice interface for GNU Debugger (GDB). I like its easy way of inspecting container types and creating conditional breakpoints:
(Stephan Avenwedde, CC BY-SA 4.0)
FakeVim
If you like Vim, enable FakeVim in the settings to control Qt Creator like Vim. Go to Tools and select Options. In the FakeVim section, you can find many switches to customize FakeVim's behavior. In addition to the editor functions, you can also map your own functions to custom Vim commands.
For example, you can map the function Build Project to the build
command:
(Stephan Avenwedde, CC BY-SA 4.0)
Back in the editor, when you press the colon button and enter build
, Qt Creator starts a build process with the configured toolchain:
(Stephan Avenwedde, CC BY-SA 4.0)
You can find more information about FakeVim in the docs.
Class inspector
When developing in C++, open the right window by clicking on the button in the bottom-right corner of Qt Creator. Then choose Outline from the dropdown menu on the top border. If you have a header file open on the left pane, you get a nice overview of the defined classes or types. If you switch to a source file (*.cpp
), the right pane will list all defined methods, and you can jump to one by double-clicking on it:
(Stephan Avenwedde, CC BY-SA 4.0)
Project configuration
Qt Creator projects are built around the *.pro-file
in the project's directory. You can add your own custom configuration to the project's *.pro-file
of your project. I added my_special_config
to the *.pro-file
, which adds MY_SPECIAL_CONFIG
to the compiler defined:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
CONFIG += my_special_config
my_special_config {
DEFINES += MY_SPECIAL_CONFIG
}
Qt Creator automatically highlights the code according to the active configuration:
(Stephan Avenwedde, CC BY-SA 4.0)
The *.pro-file
is written in the qmake language.
Summary
These features are only the tip of the iceberg of what Qt Creator provides. Beginners shouldn't feel overwhelmed by the many features, as Qt Creator is absolutely beginner-friendly. It may even be the easiest way to start developing in C++. To get a complete overview of its features, refer to the official Qt Creator documentation.
via: https://opensource.com/article/21/6/qtcreator
作者:Stephan Avenwedde 选题:lujun9972 译者:译者ID 校对:校对者ID