PDA

View Full Version : C++/Qt coding standards



derick
8th May 2008, 09:46
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:



class JumpaWidget : public QWidget

{
..
public:
QString m_PublicMember;

void setState(QString state);
QString getState();

void doSomeAction(QString aAction);
Q_SIGNALS:
void signalChanged(int);
void stateChanged(int);

private:
..
QString mState;
QString mError;
QString* mpString;

}


void JumpaWidget::doSomeAction(QString aTodo)
{
..
if(aTodo == "Jump")
{
setState("Confused");
m_Error = "How high";
}
..
}

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:


if(foo){
bar();
}
or


if(foo)
{
bar();
}
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.

wysota
8th May 2008, 10:00
Have a look at this: http://doc.trolltech.com/qq/qq13-apis.html