C++ code style | Qt Creator Documentation
Description: Set global code style for C++ files.

- Qt Creator Documentation
- C++ code style
- Qt Creator 19.0.1

Behavior ◦ C++ quick fixes

# C++ code style

Qt Creator uses the Clang LibFormat library to automatically format and indent C++ code. It enforces a coding style for a project or the whole organization.

To specify global indentation settings for the C++ editor, go to Preferences > C++ > Code Style.

The following table describes the available preferences.

Preference | Description
--- | ---
Formatting mode | Select: Indenting Only to only indent code. Full Formatting to use the Ctrl+I keyboard shortcut to format code instead of indenting. Use Built-In Indenter to turn off ClangFormat.
Ignore files greater than | Make parsing faster by ignoring big files. Specify the maximum size of files to parse.
Format while typing | Apply the formatting while you type.
Format edited code on file save | Apply the formatting to the edited code when you save the file. To temporarily disable this setting while saving a file, go to File and select Save Without Formatting.
Use custom settings | Change the ClangFormat style globally for all projects.
Custom settings | Select the settings to change, then select Copy. Give a name to the settings, and select OK.
ClangFormat | Edit the ClangFormat Style Options. The live preview shows how the preferences change the indentation. If you enter invalid values, you see warning messages.

## Using built-in indenter

If you select Use Built-In Indenter in Formatting mode, you can specify how to:

- Interpret the Tab and Backspace key presses.
- Add macros that the indenter interprets as complete statements that don't require a semicolon at the end.
- Indent the contents of classes, functions, blocks, and namespaces.
- Indent braces in classes, namespaces, enums, functions, and blocks.
- Control switch statements and their contents.
- Align continuation lines.
- Bind pointers (*) and references (&) in types and declarations to identifiers, type names, or left or right `const` or `volatile` keywords.

### Specifying settings for content

You can indent public, protected, and private statements and declarations related to them within classes.

You can also indent statements within functions and blocks and declarations within namespaces.

### Specifying settings for braces

You can indent class, namespace, enum and function declarations and code blocks.

### Specifying settings for switch statements

You can indent case or default statements, or statements or blocks related to them within switch statements.

### Specifying alignment

To align continuation lines to tokens after assignments, such as `=` or `+=`, select Align after assignments. You can specify additional settings for aligning continuation lines in the General tab.

You can also add spaces to conditional statements, so that they are not aligned with the following line. Usually, this only affects `if` statements.

### Binding pointers and references

To bind pointers (`*`) and references (`&`) in types and declarations to identifiers, type names, or left or right `const` or `volatile` keywords, select the checkboxes in the Pointers and References tab.

The `*` and `&` characters are automatically bound to identifiers of pointers to functions and pointers to arrays.

## Creating ClangFormat files from command line

You can create `.clang-format` files that have the configuration options of a certain predefined style from the command line. For example, to create a format file for the LLVM style, enter the following command:

     clang-format -style=llvm -dump-config > .clang-format

See also Indent text or code, Specify code style, Behavior, Specify Qt Quick code style, and Nim.

Behavior ◦ C++ quick fixes