How to configure the Qt development environment?
How to install?
First install the Qt environment: sudo apt install qt5-default qtcreator.
Compile dependencies of the installation project: sudo apt build-dep xxx. "xxx" is the project name, for example: sudo apt build-dep dde-control-center is the compilation dependency for installing the control center project.
In addition, before using the apt build-dep command, you need to configure the source address of the source code in /etc/apt/sources.list, that is, the source address opened with "deb-src". (The project name can be obtained in the project's debian/control file, all project names have been pre-installed in the system)
How to configure code style?
- The style is consistent with the Qt library code. Refer to: wiki.qt.io/Qt_Coding_Style (use the astyle tool to assist)
- Code comments are uniformly used in Chinese (a better understanding of the code is the priority)
- Try to use the Qt native data structure, and consider the CPP data structure when the requirements are not met (for example, the string type should use QString instead of std::string)
- Don't abuse lambda functions
- Whenever possible, use forward declarations instead of include when referencing classes
- The include of the CPP header file needs to be divided into areas, and each area is separated by a blank line
- Use blank lines to separate code blocks. For details, please refer to Qt Code Style
- Do not abuse blank lines, and are not allowed to add blank lines where they should not be added (such as the beginning and end of the function body)
- Place symbols such as ":" "," in front of class initialization
- Overriding a virtual function requires adding the override modifier
include zone division rules:
The higher the code is, the higher it is (for example, the code of the project itself should be placed at the front)
The header files of each library use a separate area (for example, all Qt library header files are placed in one area, and DTK library header files are also placed in a separate area)
Differential division example:
// Area 1: Project own files #include "xxx.h"
// Area 2: DTK library files #include <DApplication>
// Area 3: Qt library files #include <QObject>
// Area 5: Other library files #include <xxx.h>
// Area 4: CPP Standard Library Files #include <iostream>
// Area 5: Linux System Library Files #include <unistd.h>
Class initialization code example:
AAA(QObject *parent)
: QObject(parent)
, m_xxx1
, ...
, m_xxxn
{
}
Concentrate common code blocks
Most codes ending with "}" indicate the end of a block of code. as function body
void fun() {
} // space
such as if else statement
if () {
...
} // empty line if () {
...
} else {
...
} // empty line
switch statement
switch () { ... } // empty line
loop statement
for (...) { ... } // empty line while (...) { ... } // empty line
In addition, two blocks of code should also be separated by blank lines when it is obvious that they are doing two different types of things, such as:
int x = 0; // variable definition // empty line xxx.fun(); // function call // empty line return xxx;
Set the source code LICENSE
/* * Copyright (C) 2019 ~ 2019 Deepin Technology Co., Ltd.
*
* Author: zccrs <zccrs@live.com>
* Maintainer: zccrs <zhangjide@deepin.com>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Each source code file needs to contain authorization instructions at the beginning, above which is the template content. You need to modify the Author and Maintainer fields to your own name and email. In addition, it can be configured in Qt Creator to use this content as the default authorization description when creating a new file (setting item: Qt Creator => Tools => Options => C++ => File Naming
page).
Use Astyle (code formatting tool) sudo apt install astyle
In the "Qt Creator -> Help -> About Plugins -> C++" group, select to enable the "Beautifier(experimental)" plugin, and restart Qt Creator to take effect
Check "Use customized style" in the "Qt Creator -> Tools -> Options -> Beautifier -> Artistic Style" configuration item, then click the "Add" button to add the following astyle rules to the pop-up edit box
For more convenient use, you can directly set the shortcut keys for "ArtisticStyle -> FormatFile" in Qt Creator (set in the "Qt Creator -> Tools -> Options -> Environment -> Keyboard" page) ``` indent=spaces=4
style=kr
indent-labels
pad-oper
unpad-paren
pad-header
keep-one-line-statements
convert-tabs
indent-preprocessor
align-pointer=name
align-reference=name
keep-one-line-blocks
keep-one-line-statements
attach-namespaces
max-instatement-indent=120 ``` git commit
For the style, please refer to: conventionalcommits.org/zh/v1.0.0-beta.2
Keep the principle of minimal commits, a commit has only one purpose
Have you learned it? If you want to learn more, welcome to exchange and learn with us:
Telegram: t.me/deepin
Twitter: twitter.com/linux_deepin
Reddit: reddit.com/r/deepin
Discord:discord.gg/xjjkcp6H2P