[Development] Qt Coding style and C++11

Kevin Funk kevin.funk at kdab.com
Fri Sep 15 10:47:02 CEST 2017


On Friday, 15 September 2017 06:42:34 CEST André Hartmann wrote:
> Hi, since a while C++11 is allowed in Qt and there is ongoing effort
> porting e.g. examples to the new possibilities.

Slightly OT but I hope still useful: I'm out of the loop how you are doing 
these code transformations, but refactoring code to use C++11 member init can 
be largely automated via clang-tidy:
  https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.html  


More towards your question:

I think one of the real important questions here is: Do we want to do large-
scale changes on our code base? 

(1) I'd personally really like to see:
- Replacing all uses Q_DECL_OVERRIDE with override
- Replacing all uses Q_DECL_NULLPTR with nullptr

(2) And maybe your request:
- Use C++11 member initialization where possible
  (IOW: Run clang-tidy cppcoreguidelines-pro-type-member-init checker
  on code base and apply all fixes)

  
I personally think that (1) would be useful (despite it costing us a lot of 
code churn when doing the transition) because it's much easier to read 
`nullptr` than `Q_NULLPTR`, or `override` instead of `Q_DECL_OVERRIDE` in 
code. Other opinions may vary, but it's definitely more comfortable for 
newcomers to read familiar C++ keywords than custom macros.

I'd be willing to provide the patches for (1) and maybe even (2) if there's a 
clear sentiment towards the change(s).

> The section "Conventions for C++11 usage" in [1] states:
> 
>   "Note: This section is not an accepted convention yet.
>    This section serves as baseline for further discussions."
> 
> I'd like to push this discussion, because if code is converted to a new
> base, it should be clear to everyone HOW to do so.

For new code the this should be a no-brainer, IMO. So +1 from my side.

That wiki page also still talks about Q_DECL_OVERRIDE, and does not mention 
nullptr either. For new code override/nullptr should always be used.

Regards,
Kevin

> What I like to add, is to encourage the use of C++11 member
> initialisation. They are already used in QtSerialBus (from the
> beginning) and QtCreator (ongoing changes to existing codebase).
> 
> What do you think?
> 
> Best regards,
> André
> 
> [1] https://wiki.qt.io/Coding_Conventions
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development


-- 
Kevin Funk | kevin.funk at kdab.com | Senior Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel. Germany +49-30-521325470, Sweden (HQ) +46-563-540090
KDAB - The Qt, C++ and OpenGL Experts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5322 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20170915/a09c944f/attachment.bin>


More information about the Development mailing list