Results 1 to 11 of 11

Thread: What's effect of QT_BEGIN_NAMESPACE? Thanks

  1. #1

    Default What's effect of QT_BEGIN_NAMESPACE? Thanks

    What's effect of QT_BEGIN_NAMESPACE/QT_END_NAMESPACE pair? Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    It is possible to compile whole Qt inside a user-defined namespace. See configure options for more details. These macros expand as:
    Qt Code:
    1. # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
    2. # define QT_END_NAMESPACE }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    Thank you!

  4. #4
    Join Date
    Aug 2008
    Posts
    11
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    I still don't get it. This is one of those things in Qt that is not documented well.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    It is possible to compile Qt inside any given namespace. See configure -help for more details. These macros ensure that Qt classes are properly declared inside the given namespace if any.
    J-P Nurmi

  6. #6
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    What are the difference between

    Qt Code:
    1. QT_FORWARD_DECLARE_CLASS(QTableView)
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2. class QTableView;
    3. QT_END_NAMESPACE
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. class QTableView;
    To copy to clipboard, switch view to plain text mode 

    in a header file of a QtClass (like a MainWindow)?

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    Let's say one configures Qt with -qtnamespace Foo.

    1)
    Qt Code:
    1. QT_FORWARD_DECLARE_CLASS(QTableView)
    To copy to clipboard, switch view to plain text mode 
    Expands to:
    Qt Code:
    1. namespace Foo { class QTableView; }
    2. using ::Foo::QTableView;
    To copy to clipboard, switch view to plain text mode 

    2)
    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2. class QTableView;
    3. QT_END_NAMESPACE
    To copy to clipboard, switch view to plain text mode 
    Expands to:
    Qt Code:
    1. namespace Foo {
    2. class QTableView;
    3. }
    To copy to clipboard, switch view to plain text mode 

    3)
    Qt Code:
    1. class QTableView;
    To copy to clipboard, switch view to plain text mode 
    Will cause a conflict because QTableView is forward declared outside the appropriate namespace, whereas including <QTableView> in the .cpp file brings in another QTableView declared inside the namespace and <QtGlobal> says
    Qt Code:
    1. using namespace ::Foo;
    To copy to clipboard, switch view to plain text mode 
    in order to make client code compile regardless of the Qt namespace usage. So QTableView becomes ambiguous and the compiler doesn't know which one to use, QTableView or Foo::QTableView.

    Summary: Plain "class QTableView;" works as long as Qt is not compiled in a namespace. Using the macros will make your code more compatible. As far as I remember, for example the Eclipse integration requires Qt to be compiled in a certain namespace.
    J-P Nurmi

  8. The following 3 users say thank you to jpn for this useful post:

    nightghost (2nd July 2009), Phlucious (6th December 2011), xiangxw (26th September 2011)

  9. #8
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    how do you configure that option ?
    where do I put it ? inside pro file ?

    thanx

  10. #9
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    just go to the QTDIR and run configure with -help option for deatails. You declare namespace name while use configure before building Qt
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  11. #10
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    oh .. so this means I will have to compile QT separate for every project ?

  12. #11
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: What's effect of QT_BEGIN_NAMESPACE? Thanks

    if you want qt for every project in another namespace, then yes.

Similar Threads

  1. Screen Resolution stting takes effect on application !
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 30th August 2008, 13:06
  2. QFont::setPointSize() does not take effect
    By lovelypp in forum Qt Programming
    Replies: 5
    Last Post: 14th July 2008, 19:44
  3. QImage glow effect
    By MarkoSan in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2008, 06:15
  4. Designing a "slide-out" effect
    By Gray in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2007, 10:52
  5. drawing shadow effect
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 25th May 2006, 15:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.