The Ultimate Qt Community site
Home News Forum Wiki Contest FAQ Links

Go Back   Qt Centre Forum > Other > General Programming

General Programming Forum devoted to general, non-Qt programming issues.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 8th May 2008, 09:46
derick derick is offline
Novice
 
Join Date: Jan 2006
Location: France
Qt products used: Qt3, Qt4
Qt platforms used: Windows
Posts: 30
Thanks: 2
Thanked 0 Times in 0 Posts
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. }
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. }
or
Qt Code:
  1. if(foo)
  2. {
  3.  bar();
  4. }
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
Reply With Quote
  #2  
Old 8th May 2008, 10:00
wysota wysota is online now
Guru
 
Join Date: Jan 2006
Location: Warsaw, Poland
Qt products used: Qt3, Qt4
Qt platforms used: Unix/X11, Windows
Posts: 11,009
Thanks: 3
Thanked 1,550 Times in 1,503 Posts
Default Re: C++/Qt coding standards

Have a look at this: http://doc.trolltech.com/qq/qq13-apis.html

Reply With Quote
The following user says thank you to wysota for this useful post:
derick (8th May 2008)
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ coding standards guestgulkan General Programming 1 1st May 2008 09:05
coding style mickey General Discussion 2 16th March 2008 18:19
Libraries (or other methods) for coding and decoding in H263 or similar toratora General Programming 0 8th March 2007 09:16
Qt Coding/Design Standards bpetty Newbie 6 17th February 2007 09:15
what will be the coding for Menu->File->open jyoti Qt Programming 3 10th November 2006 12:16


All times are GMT +1. The time now is 16:36.

Powered by vBulletin Version 3.7.1 Copyright ©2000 - 2008, Jelsoft Enterprises Ltd., vRewrite 1.5 SEOed URLs completed by Tech Help Forum and Chalo Na.
© 2006–2008 Qt Centre - The Ultimate Qt Community site
The Qt by Trolltech logo is used with express permission of Trolltech ASA. Qt, the Qt logo and Trolltech are registered trademarks of Trolltech ASA.