camel case or underscores or mixed?



  • I noticed Qt creator uses mixed styles and I was wondering if a reason existed for this.

    It generates signals/slots that use underscores and all classes and functions seem to be camel case. Is this standard? Is this what I should do as a Qt developer?

    Is this in the docs some where?

    Thanks



  • Hi @Goddard,

    It generates signals/slots that use underscores and all classes and functions seem to be camel case.

    What do you mean by it "generates signal/slots"? I'm a bit of a Qt Creator n00b - just use it as a glorified text editor most of the time, so I'm not familiar with its code generation abilities, but what you describe does sound odd.

    Is this standard? Is this what I should do as a Qt developer?

    I'd say not. Most (all?) of the Qt classes use camelCase for signals; eg QObject::objectNameChanged.

    It generates signals/slots that use underscores and all classes and functions seem to be camel case.

    So while you're welcome (AFAIK) to use any style you like, I certainly wouldn't say underscores are recommended just based on whatever Qt Creator behaviour you're seeing.

    Cheers.


  • Moderators

    @Paul Colby

    What do you mean by it "generates signal/slots"?

    See http://doc.qt.io/qt-5/designer-using-a-ui-file.html#widgets-and-dialogs-with-auto-connect

    @Goddard said:

    It generates signals/slots that use underscores and all classes and functions seem to be camel case. Is this standard? Is this what I should do as a Qt developer?

    As a developer in general, you are free to do whatever you want. Pick your preferred style and stick to it. The most important thing is to be consistent.

    Qt Designer's auto-connector uses underscores. Unfortunately, this is inconsistent with Qt's coding conventions. Qt's public API uses camel casing only, not underscores.

    Personally, I don't use the auto-connector.

    I noticed Qt creator uses mixed styles and I was wondering if a reason existed for this.

    No good reason, really.


  • Qt Champions 2016

    @Goddard

    It generates signals/slots that use underscores and all classes and functions seem to be camel case. Is this standard? Is this what I should do as a Qt developer?

    I personally prefer camelcase, as underscore reminds me too much of C and its many quirks, and to be honest I don't see adding extra underscores as improvement on readability. Still, as JKSH said, it's just a matter of preference and you're free to choose what suits you best.

    @JKSH said:

    Personally, I don't use the auto-connector.

    Too magic for me either ...


  • Moderators

    After some time working with a giant project that uses Qt, MFC, STL nad WinAPI in different parts all I can say is that naming convention doesn't really make a difference, just do yourself a giant favor and pick one and stick to it.

    And I wouldn't use the auto connection feature. It might be tempting for people used to visual designers like in C# or Delphi, but it's quite different in details and not particularly good for maintenance anyway (renaming, refactoring etc).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.