PDA

View Full Version : Qt specific questions regaring coding style



Raistlin
24th February 2007, 10:50
I like to follow a certain coding style for my classes, following the following template :



class SomeClass : public SomeBaseClass
{

public :
void somePublicFunction();

int someVariable() const;
void setSomeVariable(const int& value);

float anotherVariable() const;
void setAnotherVariable(const float& value);

...

private:
void somePrivateFunction();
...

int someVariable_;
float anotherVariable_;

}


However, when I am working on a Qt project with for example a large QMainWindow derived class, I tend to break this style. There are so many private QAction's, QMenu's, QToolbar's and other Qt based objects that I feel they make the code less readable if I append an underscore.

Do any of you guys tend to do something similar in specific cases, or do you follow your coding style strictly on every occasion ?

Bitto
24th February 2007, 11:35
If you namespace your private data with a struct, you will avoid the name clashes.



class A {
public:
int a() const { return data.a; }
int b() const { return data.b; }
int c() const { return data.c; }

private:
struct {
int a, b, c;
} data;
};


Because the struct itself is inlined, the compiler will optimize away the dereferencing.

Brandybuck
25th February 2007, 01:52
I myself append an underscore to my data members. However, I'm starting to lean towards the "m_" prefix. If not for the inevitable clash between getters (foo()) and members (foo), I would forego special naming conventions completely.

stevey
25th February 2007, 22:55
I personally just prefix with underscore.

The issue with it is you break convention when using VS integration as the Ui object which sets up your document doesn't have the underscore. Maybe you can force it, dunno.
I just personally accept that all Qt 'designed' object won't have the underscore and don't worry about it.

You could consider that itself a convention...anything you manually define in code has the underscore.

Raistlin
26th February 2007, 09:14
In fact, that is the way I thought also to approach it. Thank you all for the input.