Use clang-format with QtCreator

Thanks to Tobias Hunger from Digia I now learned how to extend QtCreator with external tools. Not that it's difficult but he had a talk about it at the Qt Developer Days 2013 in Berlin and showed that it's very easy and powerful.

As I saw Chandler Carruth talking about clang and its tools at Going Native 2013 (just on video, no need to get jealous here), I was instantly hooked, built the tools and now want to use them inside QtCreator.

Open the preferences and add a new category if you like. This appears as a new menu entry inside the Tools/External menu.

Add a new tool, look up the binary (or script) and add its arguments

QtCreator has some variables that you can use to specify the source code file that should be processed by the external tool.

Here is one tiny example of what clang-format does for your code. Choose clang-format from the tools menu and

this code...

...turns into...

But be careful: currently QtCreator does not enable undo for such an action. Of course your source code control system fills up that gap.