Change automatic const placement in Qt Creator?
Asked Answered
B

1

6

Suppose I am creating the following function:

double f(double const& x) { return x + x; }

This is how I like to place the const modifier, not like const double. However, Qt Creator automatically places it in the other position. For example, if I declared the above function in a header file, and then use Qt Creator refactor tools to automatically add a definition in the .cpp file, I'll get const placed in the wrong place, and the & will be next to the variable, which I also don't like:

double f(const double &x) { return x + x; }

How can I modify this default behavior in Qt Creator?

Broider answered 28/4, 2015 at 19:16 Comment(4)
Easy and simple: You can't.Pumpkin
Get to Qt Creator's Options or Preferences, then: C++ -> Code Style -> <Select a code style> -> Edit... -> Pointers and References. Edit as you please. Also note that this may be overriden on a per-project basis; Look also at the per-project settings, there's a roughly analogous panel. Per-project settings will override the global setting.Mennonite
@IwillnotexistIdonotexist +1 Thanks. I can bind * and & to the type instead of the identifier. However, I do not see an option to change the const placement?Broider
@becko That's the part I don't know how to do unfortunately. But C++ -> Code Style is the place to dig in, if it's at all possible.Mennonite
Y
1

I can't add a comment to the original post, however in Qt Creator 14 (and possibly earlier) you can change the const placement through ClangFormat (it gained support for that in ClangFormat 14, so since 2022).

You need to go to your Preferences at C++ > Code Style. Check "Use custom settings" and then make a copy of the Qt style (using the Copy button). After that, you can edit the left column, and add QualifierAlignment: Right, then press Apply and OK.

Yelp answered 19/9 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.