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.

You can specify indentation for:

  • C++ files
  • QML files
  • Nim files
  • Other text files

You can 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. Select Projects > Project Settings > Code Style.

    {Code Style settings in Projects mode}

  2. In the Language field, select C++, Qt Quick, or Nim.
  3. Deselect the Use global settings check box.
  4. In the Current settings field, select the settings to modify and click Copy.
  5. Give a name to the settings and click OK.
  6. Click Edit to specify a code style 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 Disable as the formatting mode to switch ClangFormat off for the project. If you can reproduce the crash, please select Help > Report Bug to report the bug and and attach the code that triggers the crash.

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

© 2023 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.