Of course, in this particulare case, using \c new might be an even better
option.
Braces
As a base rule, the left curly brace goes on the same line as the start of the statement:
\code
// Wrong
if (codec)
{
...
...
@@ -292,8 +299,10 @@ Braces
// Correct
if (codec) {
}
\endcode
Exception: Function implementations and class declarations always have the left brace on the start of a line:
\code
static void foo(int g)
{
qDebug("foo: %i", g);
...
...
@@ -302,8 +311,10 @@ Braces
class Moo
{
};
\endcode
Use curly braces when the body of a conditional statement contains more than one line, and also if a single line statement is somewhat complex.
\code
// Wrong
if (address.isEmpty()) {
return false;
...
...
@@ -319,15 +330,19 @@ Braces
for (int i = 0; i < 10; ++i)
qDebug("%i", i);
\endcode
Exception 1: Use braces also if the parent statement covers several lines / wraps
\code
// Correct
if (address.isEmpty() || !isValid()
|| !codec) {
return false;
}
\endcode
Exception 2: Use braces also in if-then-else blocks where either the if-code or the else-code covers several lines
\code
// Wrong
if (address.isEmpty())
--it;
...
...
@@ -358,16 +373,20 @@ Braces
else
...
}
\endcode
Use curly braces when the body of a conditional statement is empty
\code
// Wrong
while (a);
// Correct
while (a) {}
\endcode
Parentheses
Use parentheses to group expressions:
\code
// Wrong
if (a && b || c)
...
...
@@ -379,10 +398,12 @@ Parentheses
// Correct
(a + b) & c
\endcode
Line breaks
Keep lines shorter than 100 characters; insert line breaks if necessary.
Commas go at the end of a broken line; operators start at the beginning of the new line. The operator is at the end of the line to avoid having to scroll if your editor is too narrow.
\code
// Wrong
if (longExpression +
otherLongExpression +
...
...
@@ -394,10 +415,7 @@ Line breaks
+ otherLongExpression
+ otherOtherLongExpression) {
}
\endcode
\section2 Declarations
...
...
@@ -424,6 +442,32 @@ Line breaks
If you create a new file, the top of the file should include a
header comment equal to the one found in other source files of Qt Creator.
\section2 Include order
Always go from less general to more general. In a typical implementation