What is the rationale for the Qt way of class naming?

I am wondering why Qt uses Q in front of every class name, rather than putting everything in a namespace. Is there any special reason, for example, to easily find names, or are they just brand names?

+6
api namespaces class qt naming-conventions
source share
6 answers

I think this is historical. Namespaces were introduced in C ++ around 1995. Qt development began in 1991, so namespaces could not be used, obviously.

+7
source share

This may be a portability issue. Namespaces were not supported / not supported by each compiler, so the naming convention helps reduce name conflicts.

+3
source share

Qt is very conservative in the features of the C ++ language that it uses. No namespaces, exclusions, or RTTIs . See Also in this article , which describes in detail why patterns are not used in signal / slot processing.

+2
source share

The documentation for Qt relates to namespaces , although I did not check the code to make sure they are really C ++ namespace or hack public declarations inside the class. I would suggest that the rest are trying to avoid that everyone can rename everything, although they could provide a migration path if they wanted, for example:

 namespace Qt { class Object { ... }; } #ifndef NO_OLD_DECLS typedef Qt::Object QObject; #endif 
+2
source share

Seeing that there is not a single C ++ compiler left that does not implement namespaces, currently there is only one reason: Branding :)

0
source share

Qt uses the Q prefix as part of its coding style. Usually this serves to simplify reading the code and determining what is.

Identifier that:

  • has the prefix "Q" and the suffix with "Private" is a private class that is used for implementation details and is not part of the API (for example, QPainterPrivate)
  • has the prefix "Q", and not , the suffix with "Private" is an open class (for example, QWidget)
  • has the prefix "q" (lowercase) - a public global function (for example, qRgb)

Adopting a coding style and using it evenly makes it easier for other people to understand code that they don’t write.

Ref .: Qt coding style

0
source share

All Articles