-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Code Style
Chris Rizzitello edited this page Feb 28, 2026
·
75 revisions
Our code formatting is enforced via CI.
Tip
See our guide: Clang‐Format Tips & Tricks
Deskflow is reuse compliant and requires reuse lint to pass in order to build New files Must include license info. Either in a comment at the top of the file or in the REUSE.toml file
Examples:
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) xxxx Deskflow Developers
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) xxxx - xxxx MY name <myemail>
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) xxxx - xxxx Deskflow Developers
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
more info: https://spdx.dev/learn/handling-license-info/
- Function names should be
camelCase(for both class member functions and free functions) - Namespaces should be all lower case and begin with
deskflow, e.g.deskflow::gui - Member variables should be prefixed with
m_helloWorld - Static variables should be prefixed with
s_, e.g.s_helloWorld - Pointers should begin with a lower case
p, e.g.m_pHelloWorld - Getters should not have
getprefixed, e.g.helloWorld() - Setters should have
setprefixed, e.g.setHelloWorld(...) - Enum values and constants should be pascal case, e.g.
HelloWorld(formerly enums began withk) - Class filenames should be pascal case, e.g.
HelloWorld.cpp - Files with many classes or functions should be snake case, e.g.
hello_world.cpp - Unit test names should follow the function-input-output pattern, e.g.
helloWorld_fooIn_barOut - The word "deps" should be used to mean "dependencies"
- You must use
Q_SIGNALSin place ofsignals - You must use
Q_SLOTSin place ofslots - You must use
Q_EMITin place ofemit
- Qt Controls SHALL NOT use a
pto indicate they are a pointer. - Qt Controls SHALL be named
<type><Description>(lblShortName) OR<type>_<lenghtyDescription>(lbl_longerNamesMayUseThisStyle) - Qt signals should indicate that something happened, e.g.
nameChanged
- Members of UI forms SHALL NOT use the
m_prefix (i.e lblError NOT m_lblError) - Don't use the autoconnection conventions (
on_foo_bar) oronFooBar. - Ui Forms should always be in the namespace
Ui- Always use
ui{std::make_unique<Ui::Type>()}make the ui instance - The Ui Form SHALL be a private member of the class using
- The variable name SHALL be
ui
- Always use
- Ui Forms should never have connections internally
- When editing ui files take extra care to not accidentally change
- item sizes
- the current item on container based widgets.
-
labelQLabels that are a static label -
lblQLabels you will be changing programmatically -
rbQRadioButton -
cbQCheckBoxe -
comboQComboBox -
btnButtons (Tool or Push) -
actionQAction - Others name without the Q
-
.cppfiles should be ordered:- Copyright
- Headers
using- Constants
- Free functions
- Class members
- Headers should be ordered in separate groups of:
- Header file for the
.cppfile - For Qt, the
.uifile - Project header files
- 3rd party lib and system headers
- Header file for the
- Getters should be grouped together
- Setters should be grouped together
- Getters and setters should not be paired
- Use ctor dependency injection (e.g.
std::functionor aDepsstruct) - A unit test body should follow the AAA (arrange-act-assert) pattern, e.g.:
auto foo = "hello"; auto bar = "world"; auto baz = combine(foo, bar); EXPECT_EQ(baz, "hello world"); - A unit test should test only one scenario and expectation
- Split test scenarios into separate test functions
- Do not allow exceptions to propagate to Qt (instead, use
qFatal())- Remember:
qFatalon Windows for debug builds, will instead report _CRT_ERROR to connect your debugger to the app
- Remember:
- Do use exceptions for exceptional situations (things that should not happen)
- Do not use exceptions for validation (e.g. if a user input value is unexpected)
- Use
DEBUGfor debug messages that do not occur frequently. - Use
DEBUG1for debug for high-frequency messages. - Use
DEBUG2for debug messages that are very high frequency (e.g. events system). - Omit function names from log strings because (it's impractical to keep them consistent long-term).
- Use lower case for our log lines, instead of sentence case.
- End log messages with numeric data if possible.
- Wrap inserted strings with single quotes.
- Do not end log messages with a period character.
- A comma can be used to make the log line read easier.