Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Namespace vs. Prefix - recommended naming practice for Qt libraries
QtWS25 Last Chance

Namespace vs. Prefix - recommended naming practice for Qt libraries

Scheduled Pinned Locked Moved 3rd Party Software
4 Posts 3 Posters 6.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Uwe Kindler
    wrote on last edited by
    #1

    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)?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          Uwe Kindler
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved