PDA

View Full Version : Qt Coding/Design Standards



bpetty
14th February 2007, 19:18
I was wondering if there are Qt coding standards out there that Troll Tech recommends when developing applications under its framework.

For example I notice they do a lot of "camel humping", example: "testVariable".
lol, sorry.. I just re-read the sentence above. Anyways...

It is just something I am interested in from a software engineering stand point. It notice that it conflicts with my companies current notation.

Also, for things like QTabWidgets... at first I put all of my components on each tab page. I realized that this was a very bad design decision because the .ui will create one class for the dialog which really hinders re-use and adaptability. Instead I am leaving these pages blank and adding a widget "frame" to each page so that each tab page has its own "frame" class.

It is stuff like that, that interests me. I am curious if Troll Tech has any design recommendations. Layouts would be another thing. Do they recommend layouts all of the time, only in certain situations... how that is important for localization... etc.

If anyone has any thoughts on this, I would love to hear them.

Thanks.

Brandybuck
14th February 2007, 19:30
Trolltech does not recommend any particular programming style. What you choose is up to you.

As for "camel humping", there tends to be three sorts of variable naming conventions:

1) c_underlining: name_your_variables_like_this
2) camelNotation: variablesThatHaveAHumpInTheMiddle
3) mshNotation: Microsoft's Hungarian Notation

The Hungarian Notation seems to be the most popular in Microsoft shops, because Microsoft used to heavily encourage it. But it's been shown to be counter productive. The prefixes are extraneous and if you don't get them exactly correct, you waste time in code review meetings correcting them.

jacek
14th February 2007, 20:48
Layouts would be another thing. Do they recommend layouts all of the time, only in certain situations... how that is important for localization... etc.
I remember that this was discussed somewhere, but I don't remeber where. It might be in "C++ GUI Programming in Qt3", but I'm not sure. Anyway, when using layouts you can avoid some problems with localization, since widgets (especially labels) can adapt to text size, which might differ between languages.

When it comes to naming conventions, read this: http://doc.trolltech.com/qq/qq13-apis.html --- the Trolls give some rationale behind naming conventions used in Qt.

jacek
14th February 2007, 20:57
Trolltech does not recommend any particular programming style. What you choose is up to you.
That's right and there always be someone that's not happy with the current style.


it's been shown to be counter productive.
Also you don't need it in C++, because it has strict type checking in comparison to C for which than notation was invented.

yop
14th February 2007, 22:16
The link (http://doc.trolltech.com/qq/qq13-apis.html) that jacek provided is a must read if you are using Qt. This will save you from inconsistent naming of the underlying framework with your code. Believe me it's a relief, the code becomes readable from the one instant to the other. I am also quite a huge fun of the convention used in http://www.javaranch.com/style.jsp although java centric and although I just can't lose the m_ prefix (yet?). But I 'm a huge Kathy Sierra fan so go figure :rolleyes:
In any case if you are using a base toolkit that will appear everywhere in your code, stick with the toolkit naming conventions...

VireX
17th February 2007, 05:43
I do not know what "notation" or "style" this is, but the standard, or more OO way to code, is naming variables like so:

QTabWidget that is in a class:
m_TabWconversations;

Standard stuff in a class:
int m_iNum;
char m_cName;

standard stuff not in a class:
int iNum;
double dbDigits;
QPushButton qpbQuit;

wysota
17th February 2007, 09:15
The last part looks like the hungarian notation and it's definitely not object-oriented and also not a standard for c++. It was created for C Windows programming and is widely explained in Paetzold's book (sorry if I mispelled the name, I don't have the book).