PDA

View Full Version : What's effect of QT_BEGIN_NAMESPACE? Thanks



mihayinoviki
12th September 2008, 04:59
What's effect of QT_BEGIN_NAMESPACE/QT_END_NAMESPACE pair? Thanks

jpn
12th September 2008, 06:58
It is possible to compile whole Qt inside a user-defined namespace. See configure options for more details. These macros expand as:


# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
# define QT_END_NAMESPACE }

mihayinoviki
12th September 2008, 08:29
Thank you!

Antebios
21st April 2009, 23:37
I still don't get it. This is one of those things in Qt that is not documented well.

jpn
22nd April 2009, 00:40
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.

PaceyIV
2nd July 2009, 20:53
What are the difference between



QT_FORWARD_DECLARE_CLASS(QTableView)


and



QT_BEGIN_NAMESPACE
class QTableView;
QT_END_NAMESPACE


and



class QTableView;


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

jpn
2nd July 2009, 22:14
Let's say one configures Qt with -qtnamespace Foo.

1)


QT_FORWARD_DECLARE_CLASS(QTableView)

Expands to:


namespace Foo { class QTableView; }
using ::Foo::QTableView;


2)


QT_BEGIN_NAMESPACE
class QTableView;
QT_END_NAMESPACE

Expands to:


namespace Foo {
class QTableView;
}


3)


class QTableView;

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


using namespace ::Foo;

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.

Rockem
19th August 2009, 09:57
how do you configure that option ?
where do I put it ? inside pro file ?

thanx

faldzip
19th August 2009, 15:50
just go to the QTDIR and run configure with -help option for deatails. You declare namespace name while use configure before building Qt

Rockem
19th August 2009, 19:21
oh .. so this means I will have to compile QT separate for every project ?

nightghost
19th August 2009, 20:21
if you want qt for every project in another namespace, then yes.