Results 1 to 3 of 3

Thread: What is the benefit of QT_BEGIN_NAMESPACE?

  1. #1
    Join Date
    Oct 2009
    Posts
    7
    Thanks
    3
    Platforms
    Windows

    Default What is the benefit of QT_BEGIN_NAMESPACE?

    I've seen things like:
    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2. QT_END_NAMESPACE
    To copy to clipboard, switch view to plain text mode 
    in a few samples. But as far as I can tell it just replaces #includeing the proper header. What's the benefit of using QT_BEGIN_NAMESPACE over #include?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: What is the benefit of QT_BEGIN_NAMESPACE?

    As far as I know - right now - QT_BEGIN_NAMESPACE is not every time expanded. So normally it does nothing and therefor it is better since "class foo" is better than "#include foo" (forward declaration).
    It is only expanded when you use Qt inside other namespaces and stuff like that...

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is the benefit of QT_BEGIN_NAMESPACE?

    Lykurg is correct, you can specify a namespace when you compile Qt, and these macros will use that namespace if its defined, or just expand to nothingness.

    The rest is standard C++ - if you have no requirement to access the members of the object (QPushButton in this case), then using a forward reference is faster for the compiler to compile than #include'ing its header (apart from maybe when you use pre-compiled headers). If you look in the Qt source, forward declarations are used a lot so that an object doesn't include everything it depends on unless you really need it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.