Configuring the coding style and coding format options

Readable code is crucial, and Qt Creator's default coding style is one that most people find very readable. However, you might be on a project with different coding guidelines, or you might just find that you can't bear a particular facet of how the Qt Creator editor deals with code formatting; maybe it's the positioning of the brackets or how a switch statement gets formatted. Fortunately, Qt Creator is extremely configurable. Go to Tools | Options | C++ and configure how Qt Creator will format your code, as shown in the following screenshot:

Configuring the coding style and coding format options

The basic dialog lets you pick popular formatting styles, such as Qt's default format or the format used by most GNU code. You can also click on Edit, which brings up the code style editor, which you can see in the next screenshot:

Configuring the coding style and coding format options

You'll want to begin by copying a built-in style and editing it to suit your tastes; from the Edit Code Style dialog, you can select whether tabs are spaces or tabs, the number of spaces per tab stop, as well as how line continuations are handled. Each pane lets you adjust specific aspects of code formatting:

  • The Content pane lets you adjust how class bodies are formatted, including spacing for public, protected, and private declarations
  • The Braces pane lets you control formatting that pertains to braces
  • The "switch" pane lets you control the switch and case statement formatting
  • The Alignment pane lets you control how code is aligned between consecutive lines
  • The Pointer pane lets you control spacing around pointer declarations

It's easy to go crazy with all these options, but I urge you not to; what looks good at first glance is often an unreadable mess when you see it day after day. If you're just getting started with Qt, stick to the default formatting and remember the old adage "do no harm" when it comes to editing the existing code—match the formatting that's already there.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset