Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-37137

Document QT_BEGIN_NAMESPACE, QT_FORWARD_DECLARE_CLASS and related defines

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.2.1
    • Documentation
    • None
    • All

    Description

      When first starting out in QT you run across QT_BEGIN_NAMESPACE right away. It's not at all obvious what this does or how to find out about it. Even after looking it up in qglobal.h it's hard to discern what the best practice for using these defines would be. In addition when looking at the example code these defines often seem to be improperly used. For example:
      In the activeqt\dotnet\wrapper\lib\tools.h (chosen at random because it was simple) you'll see the following:

      QT_BEGIN_NAMESPACE
      class QString;
      QT_END_NAMESPACE
      
      System::String *QStringToString(const QString &qstring);
      QString StringToQString(System::String *string);
      
      #endif // TOOLS_H
      

      I don't see how this would compile if Qt were actually in a namespace. The forward declaration of the class QString is correct but the usage as a parameter to QStringToString() is not. It looks to me like the example should be:

      System::String *QStringToString(const QT_PREPEND_NAMESPACE(QString) &qstring);

      That said, I'm still unclear as to whether users should even bother trying to make their code immune to Qt being inside a namespace or not. Some official documentation and recommendations would be much appreciated.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            docteam Qt Documentation Team
            rolias Tod Gentille
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes