Skip to content

Instantly share code, notes, and snippets.

@Uflex
Last active November 3, 2019 16:19
Show Gist options
  • Save Uflex/7086827 to your computer and use it in GitHub Desktop.
Save Uflex/7086827 to your computer and use it in GitHub Desktop.
Configuration of clang-format for QtCreator

QtCreator doesn't allow using clang-format by default. Watch QTCREATORBUG-10111 for a better integration. For now, you should use it as an external tool, either replacing your selection (described below) or the entire file.

For Windows, download LLVM from http://llvm.org/builds/. You don't need to add it to the PATH, you can use it with the absolute path.

In QtCreator, add an external tool (Tools > Options... > Environment > External Tools > Add > Add Tool).

  • Arguments:
    -style="{BasedOnStyle: llvm, ColumnLimit: 80, Standard: Cpp11, IndentWidth: 4, BreakBeforeBraces: Linux}"
  • Working dir: %{CurrentProject:Path}
  • Output: replace selection
  • Error output: show in pane
  • Don't tick the "Modifies current document"
  • Input: %{CurrentDocument:Selection}

See these for all possible parameters:

@NLKNguyen
Copy link

Thank you! It works nicely.

@cyc1ingsir
Copy link

Thanks! This definitely put me on the right track!
However, for the beautifier entry to appear within the Tools->Options the Beautifier plugin must be enabled first. With version 3.5.x it's still not enabled by default.
Enabeling can be done via Help -> About Plugins.
Ctrl+Shift+I collides with Open Include History (on QtCreator-Linux at least). I've tied this to Ctrl+Alt+I.
Also, if you want to modify the default styles, check [X] Use customized styles.
In the dialog appearing when clicking add just set a name of your choice and within the value field, add a comma separated list of options. e.g.
BasedOnStyle: llvm, ColumnLimit: 100, IndentWidth: 4, Standard: Cpp11, PointerBindsToType: false, BreakBeforeBraces: Linux, BreakConstructorInitializersBeforeComma: true, AccessModifierOffset: -4, BreakBeforeBinaryOperators: true ...
I've found (http://clangformat.com/) quite useful for explaining the options.

@kogorek
Copy link

kogorek commented Mar 11, 2017

Thank you!

@ccseer
Copy link

ccseer commented Jun 12, 2017

Thank you! *2

@pikapi12321
Copy link

nice~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment