Is it important to declare the namespace with QT_BEGIN_NAMESPACE .. QT_END_NAMESPACE
Asked Answered
R

2

20

What is the effect of QT_BEGIN_NAMESPACE?

QT_BEGIN_NAMESPACE
class QLineEdit;
QT_END_NAMESPACE

If I don't use the class declaration like that, will any problem occur?

Revolution answered 27/7, 2010 at 7:3 Comment(2)
Check out this qtcentre.org/threads/…Hestia
wiki.qt.io/Qt_In_NamespaceAdila
P
23

QT_BEGIN_NAMESPACE and QT_END_NAMESPACE are preprocessor macros and they are defined in QtGlobal as:

#define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
#define QT_END_NAMESPACE }

But: those two macros only have any effect when Qt was configured and built using the -qtnamespace option, which allows you to build Qt inside a user-defined namespace.

So: if you don't use (or plan on using) a Qt library which was built this way (per default, the Qt library resides in the global namespace), omitting the QT_BEGIN_NAMESPACE and QT_END_NAMESPACE won't lead to any problems.

Publicly answered 27/7, 2010 at 7:45 Comment(0)
U
0

if you do not use them, it may crash in certain scenarios.

The Qt-in-Namespace feature serves as a tool to handle certain scenarios involving multiple configurations of Qt more gracefully. E.g. before Qt-in-Namespace a Qt 3 based application in Linux would immediately segfault as soon as it tries to dlopen() a shared object that is linked to Qt 4. With the Qt in namespace feature not only can the crash be prevented, but under certain circumstances this combination might actually "work". source

Underwent answered 14/9, 2021 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.