Results 1 to 2 of 2

Thread: C++/Qt coding standards

  1. #1
    Join Date
    Jan 2006
    Location
    France
    Posts
    36
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default C++/Qt coding standards

    Hi,

    I have some thoughs about “Qt coding standards”. I've seen various standards, for example this link http://www.possibility.com/Cpp/CppCodingStandard.html and then code the Trolls wrote.

    I'm wondering about naming conventions of members for example:

    Qt Code:
    1. class JumpaWidget : public QWidget
    2.  
    3. {
    4. ..
    5. public:
    6. QString m_PublicMember;
    7.  
    8. void setState(QString state);
    9. QString getState();
    10.  
    11. void doSomeAction(QString aAction);
    12. Q_SIGNALS:
    13. void signalChanged(int);
    14. void stateChanged(int);
    15.  
    16. private:
    17. ..
    18. QString mState;
    19. QString mError;
    20. QString* mpString;
    21.  
    22. }
    23.  
    24.  
    25. void JumpaWidget::doSomeAction(QString aTodo)
    26. {
    27. ..
    28. if(aTodo == "Jump")
    29. {
    30. setState("Confused");
    31. m_Error = "How high";
    32. }
    33. ..
    34. }
    To copy to clipboard, switch view to plain text mode 
    The getter and setter methods (setXXXX and getXXXX) are fine and nice since code completion helps me and I know I want to set some variable/state in the class.


    Attributes? sError, msError, m_ErrorString; If it were two error variables I would say m_ErrorCode and m_ErrorString for example.


    Is it really important to ‘encode’ the variable type into the name? My guess is not really since we have type checking. But one should consider readability for the next person.

    Indent/braces: Then when it comes to placing the braces:
    Qt Code:
    1. if(foo){
    2. bar();
    3. }
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. if(foo)
    2. {
    3. bar();
    4. }
    To copy to clipboard, switch view to plain text mode 
    I personally prefer the 2nd one since the code is (arugably) more readable, easier to scan "blocks" of code.

    Please provide some feedback or give me some example of your 'correct' coding standard. I know that each person/organization has a personal touch but there are some 'best practice' conventions out there. I'm especially interested in the Qt world's coding habits.
    Derick Schoonbee

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: C++/Qt coding standards


  3. The following user says thank you to wysota for this useful post:

    derick (8th May 2008)

Similar Threads

  1. c++ coding standards
    By guestgulkan in forum General Programming
    Replies: 1
    Last Post: 1st May 2008, 09:05
  2. coding style
    By mickey in forum General Discussion
    Replies: 2
    Last Post: 16th March 2008, 18:19
  3. Replies: 0
    Last Post: 8th March 2007, 09:16
  4. Qt Coding/Design Standards
    By bpetty in forum Newbie
    Replies: 6
    Last Post: 17th February 2007, 09:15
  5. what will be the coding for Menu->File->open
    By jyoti in forum Qt Programming
    Replies: 3
    Last Post: 10th November 2006, 12:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.