October 19, 2010

Uwe Kindler Uwe Kindler
Lab Rat
53 posts

Namespace vs. Prefix - recommended naming practice for Qt libraries

 

Normally If I develop a certain C++ library I put my data and classes into C++ namespaces. In the Qt library and certain Qt related libraries like Qxt or Qwt no namespaces are used but all data and classes qre prefixed (Qt library – Q, Qxt library – Qxt, Qwt library – Qwt). So I would like to know if there is a recommended practice for naming when developing a library that uses Qt classes and provides classes derived from Qt.

We have a Qt vision library here and I’m not sure whether to put all the library stuff into Qvi namespace or to go the Qt way and prefix all classes and data with Qvi prefix and ignore namespaces. A third solution would be to mix both – that means put all data prefixed with Qvi into Qvi namespace.

What would a Qt developer recommend here? Was there a certain reason for not using namespaces for Qt (i.e. maybe old C++ compilers did not support namespace properly)?

3 replies

October 19, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1607 posts

In common usages I can’t say anything against namespaces. If you will use QtScript and bindings in case of namespace you should explicitly use them at types registering.
Also Qt itself can be placed into namespace during configure via -qtnamespace coption.

October 19, 2010

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

I certainly recommend to use namespaces!

The Prefixing is from my understanding mostly a relict from the dark ages when compilers did not yet support those properly. Once done it is hard to change from prefixes to namespaces, but even Qt can be configured to use namespaces nowadays and we most certainly use them e.g. in Qt Creator.

October 19, 2010

Uwe Kindler Uwe Kindler
Lab Rat
53 posts

Thank you. This was also my first intention but I was not sure that it is the “Qt way” of doing things so your answers are very valuable feedback for me.

 
  ‹‹ Plotting library      [Solved] Gsoap with nokia Qt SDK problems ››

You must log in to post a reply. Not a member yet? Register here!