Beautifying Source Code

You can use the experimental Beautifier plugin to format your source code by using the following external tools:

The Beautifier plugin parses the source code into component structures, such as assignment statements, if blocks, loops, and so on, and formats them as specified in the Beautifier options. You can use a predefined style or define your own style.

To use the Beautifier plugin:

  1. Download and install the tool to use for formatting source code:

    You might have to build the tools from sources for some platforms.

  2. Select Help > About Plugins > C++ > Beautifier to enable the plugin.
  3. Restart Qt Creator to be able to use the plugin.
  4. Select Tools > Options > Beautifier to specify settings for the tool you want to use.

  5. In the Artistic Style command, Clang Format command, or Uncrustify command field, specify the path to the tool executable.
  6. In the Options group, select the configuration file that defines the style to use in the source files. If you select several options, they are applied from top down.
    • Select the Use file defined in project files option to use the configuration file defined in the qmake DISTFILES variable as the configuration file for the selected tool.
    • Select the Use file in $HOME option to use the specified file in the user's home directory as the configuration file for the selected tool.
    • Select the Use customized style option, and then Add to define your own style.

      Define code formatting in the Edit Configuration dialog. It provides syntax highlighting, auto-completion, and context-sensitive help. For these features, you must have the tool installed.

  7. Select Tools > Beautifier > Artistic Style, ClangFormat, or Uncrustify > Format Current File to format the currently open file.

    You can create keyboard shortcuts for the functions.

In addition to the Format Current File command, ClangFormat and Uncrustify provide the Format Selected Text command. If you select it when no text is selected, nothing happens. To format the entire file in this case when using Clang, select the Format entire file if no text was selected check box in the Clang Format options.

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