Specify code style

The MIME type of the file determines which mode and editor the file opens in. Qt Creator opens C++ files in Edit mode in the C++ code editor and QML files in the Qt Quick editor.

Specify indentation for:

  • C++ files
  • QML files
  • Nim files

Specify code style either globally or separately for each project. You can specify several sets of code style settings and easily switch between them. In addition, you can import and export code style settings.

To override the global code style for the current project:

  1. Go to Projects > Project Settings > Code Style.

    {Code Style settings in Projects mode}

  2. In Language, select C++, Qt Quick, or Nim.
  3. For C++, clear Use global settings to use the .clang-format file for the project.
  4. To override the project's .clang-format file, select Use custom settings.
  5. In Custom settings, select the settings to use for the project.

In rare cases, ClangFormat can trip over a code construct and trigger a Qt Creator crash. If that happens for your project, select Use Built-In Indenter in Formatting mode to turn off ClangFormat for the project. If you can reproduce the crash, go to Help > Report Bug to report the bug and attach the code that triggers the crash to the bug report.

See also Indent text or code, Edit MIME types, C++ Code Style, Qt Quick Code Style, and Nim.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.