Skip to content

Naming and Coding Conventions

Michael Faath edited this page Jan 23, 2014 · 1 revision

General

Use meaningful names.

Don't use abbreviations.

If your class can be contained in a list also introduce a list type. Don't forget the Q_DECLARE_TYPENAME.

Only inherit from QObject if really necessary.

File names

Only lower case, underscores only if really necessary.

A file should be called like the biggest class / function it contains.

Classes

CamelCase, no prefix or underscores.

First letter must be in upper case.

Should be called like the file it is in.

Every class must have a constructor and destructor.

Base classes which do not derive from other classes must have a virtual destructor.

Function names

CamelCase, no underscores.

First letter must be in lower case.

Function parameters

All but pointers and primitive types have to be passed as const reference.

getter/setter

No "get"-prefix for getter functions, they must be called like the variable it gets.

A getter must be const.

"set"-prefix for setter functions, must only contain one parameter. Must be named like the variable it sets.

Set functions have to compare the new value with the old value, only if they differ the new is set (and only emit a signal if the value changed!).

Member variables

All classes which are exported have to use a private implementation.

All other member variables must be prefixed "m_" and named like local variables.

Global variables

Do not use!

Local variables

CamelCase, first letter must be in lowercase.

Scripting

Give a variable only to scripting if it is really necessary.

All variables accessible by the scripting must have a getter, setter and a signal for changes. They must be marked by Q_PROPERTY.

Functions called by the scripting have to be SLOTS or Q_INVOKABLE.

Don't forget to use qmlRegisterMetatype() for all classes used in the scripting.

Clone this wiki locally