[Qt-interest] Qt coding guidelines/conventions
Gabriel M. Beddingfield
gabrbedd at gmail.com
Thu Mar 25 14:49:59 CET 2010
On Thu, 25 Mar 2010, Mandeep Sandhu wrote:
> eg I've seen in Qt, member variables have a "m_" prefixed to
> them...something similar is mentioned in the MythTV guidelines which
> uses Qt (http://www.mythtv.org/wiki/Coding_Standards)
m_ is fairly standard... even amoung projects that don't use
hungarian notation. However, I've personally switched to
just _ for member variables (since I don't use HN).
Definately find /some/ way to mark member variables. It
makes the code much easier to follow.
FWIW, I'm a better man for reading Qt's source code.
> Also, since I no longer have the luxury of automatic garbage
> collection (ah...I miss java! :P) and guidelines on how to protect
> yourself from those nefarious memory leaks?
>
> Some helpful stuff I found was using QPointer, which makes the task of
> checking for dangling pointers easy.
Some manner of smart pointer is the way to go. You should
also check out:
std::auto_ptr<> Basic managed pointer, not shared
boost::shared_ptr<> A reference-counted pointer
boost::weak_ptr<> Similar to QPointer
Also good books on C++ (incl. style):
"Thinking in C++" Vol 1 & 2
by Bruce Eckel
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
-gabriel
More information about the Qt-interest-old
mailing list