Style Guidelines and Naming Conventions

C++ is a powerful language that supports many different programming styles. The coding style used in most Qt programs is not "pure" C++. Instead, it uses combination of macros and preprocessor trickery to achieve a higher-level dynamic language that more closely resembles Java or Python than C++. In fact, to take full advantage of Qt's power and simplicity, we tend to abandon the Standard Library entirely.

We find there are certain aspects to "Qt programming style" that are worth emulating, and they are summarized here. For a more complete guide, see "Designing Qt-Style C++ APIs," by Matthias Ettrich, published by Trolltech.

  • Class names begin with a capital letter: class Customer
  • Function names begin with a lowercase letter.
  • Although permitted by the compiler, periods, underscores, dashes, and funny characters should be avoided whenever possible (except where noted below).
  • Multi-word names have subsequent words capitalized: class FileTagger void getStudentInfo() for example.
  • Constants should be in CAPS.
  • Each class name should be a noun or a noun phrase: class LargeFurryMammal; for example.
  • Each function name should be a verb or a verb phrase: processBookOrder(); for example.
  • Each bool variable name should produce a reasonable approximation of a sentence when used in an if() statement: bool isQualified; for example.

For data members, we use a common prefix.

  • Member name: m_Color, m_Width (prepend lowercase m_)
  • static data members: sm_Singleton, sm_ObjCount

For each attribute, we have naming conventions for their corresponding getters/setters.

  • Non-boolean getters: color() or getColor()[8]

    [8] The latter is Java style, the former is Qt style. Both conventions are widely used. Try to be consistent in your code.

  • Boolean getters: isChecked() or isValid()
  • Setter: setColor(const Color& newColor);

A consistent naming convention greatly improves the readability and maintainability of a program.


Part I: Introduction to C++ and Qt 4

C++ Introduction

Classes

Introduction to Qt

Lists

Functions

Inheritance and Polymorphism

Part II: Higher-Level Programming

Libraries

Introduction to Design Patterns

QObject

Generics and Containers

Qt GUI Widgets

Concurrency

Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments

Bibliography

MP3 Jukebox Assignments



An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net