[Qt-creator] Settings for code generation

Dmitriy Purgin dpurgin at gmail.com
Fri Mar 20 08:18:03 CET 2020


Hi Leander,

thanks a lot for looking into this, this is something that really could be
improved in Qt Creator. I think that all the points you mention are valid
and should be available as settings, preferably at both (sub-)project and
global level. As an example, we have a customer project consisting of
multiple parts (Framework/SDK and multiple end products), which of them may
adopt different coding styles and naming conventions.

There are also a couple of options I would add to the generator:
* Generate signals with or without the new value (e.g.: valueChanged(int
newValue) vs. valueChanged())
* Generate the code using the d-pointer (e.g.: int value() const { return
d->m_value; }) with all the naming options (m_value, value, value_)
* Optionally Q_REQUIRED_RESULT or [[nodiscard]] attribute for getters

Yes, these are a lot of possibilities... Looking forward to testing your
new features!

Cheers
Dmitriy


On Wed, Mar 18, 2020 at 11:52 AM Leander Schulten <
leander.schulten at rwth-aachen.de> wrote:

> Hello,
>
> I am currently working on an improved version of the C++ QuickFixes for
> the generation of getters, setters, signals, Q_PROPERTY described in
> QTCREATORBUG-1532 <https://bugreports.qt.io/browse/QTCREATORBUG-1532>.
> But I think new settings are needed to configure that code generation,
> otherwise you have options like:
>
>    - Generate Getter in Header
>    - Generate Getter in Source
>    - Generate Getter Outside Class
>    - Genervte Setter in Header
>    - …
>    - Generate Getter in Header and Setter in Source
>    - …
>    - Generate Q_PROPERTY, Getter in … and Setter in …
>    - …
>
> There was already a Bug with a similar Problem (QTCREATORBUG-16452
> <https://bugreports.qt.io/browse/QTCREATORBUG-16452>): Should the
> function name of a getter <name> or get<name>? A new Settings was
> introduced at Menu: Tools > Options > Tab: Code Style > Button "Edit..." -
> in the upcoming dialog, in the tab "Getter and Setter" you can uncheck
> "Prefer getter names without "get" to get the desired behaviour.
> Maybe the setting can be moved to the Menu: Tool > Options > C++ > Qt
> Class Generation or you introduce a new tab "Quick Fix Style". There you
> can also define the naming convention of member variables (m_*name*,
> *name*, *name*_, ...), if you want to use slots for setters or where
> implementations of setter/getter should be placed (Inside/Outside-Class,
> .cpp file). Different "Quick Fix Style” should be possible for different
> projects. Maybe save the styles in a file and load them like the clang
> format file, so that everyone in a project uses the same generation rules.
> Currently every QuickFix does something different: The
> InsertQtPropertyMembers QuickFix place the implementations inside the
> class, the GenerateGetterSetter QuickFix place the implementations in the
> .cpp file.
>
> How should the new settings be implemented?
>
> I have already implemented the generation for headers and started the
> implementation for source files, when I realised that there are far too
> many possibilities.
>
> Regards,
> Leander Schulten
>
>
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at qt-project.org
> https://lists.qt-project.org/listinfo/qt-creator
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20200320/b90283f5/attachment.html>


More information about the Qt-creator mailing list