Wofür der Macro "QT_BEGIN_NAMESPACE"
-
Hallo Zusammen,
bei Qt5 ist mir aufgefallen die Benutzung von dieses Macro QT_BEGIN_NAMESPACE.
z.b:QT_BEGIN_NAMESPACE class QAction; class QCheckBox; class QComboBox; class QGroupBox; class QLabel; class QLineEdit; class QMenu; class QPushButton; class QSpinBox; class QTextEdit; QT_END_NAMESPACE //! [0] class Window : public QDialog { Q_OBJECT public: Window(); void setVisible(bool visible) Q_DECL_OVERRIDE; protected: void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; private slots: void setIcon(int index); void iconActivated(QSystemTrayIcon::ActivationReason reason); void showMessage(); void messageClicked(); private: void createIconGroupBox(); void createMessageGroupBox(); void createActions(); void createTrayIcon(); QGroupBox *iconGroupBox; QLabel *iconLabel; QComboBox *iconComboBox; QCheckBox *showIconCheckBox; QGroupBox *messageGroupBox; QLabel *typeLabel; QLabel *durationLabel; QLabel *durationWarningLabel; QLabel *titleLabel; QLabel *bodyLabel; QComboBox *typeComboBox; QSpinBox *durationSpinBox; QLineEdit *titleEdit; QTextEdit *bodyEdit; QPushButton *showMessageButton; QAction *minimizeAction; QAction *maximizeAction; QAction *restoreAction; QAction *quitAction; QSystemTrayIcon *trayIcon; QMenu *trayIconMenu; };
Wie wichtig ist dieses Macro?
Danke
-
This
QT_BEGIN_NAMESPACE
macro is used to wrap Qt classes in the (optional)QT_NAMESPACE
namespace. The Qt libraries that ship pre-compiled from the Qt website, as well as those in most OS distributions are built without any wrapping namespace (ieQT_NAMESPACE
is empty, andQT_BEGIN_NAMESPACE
does nothing). However, in some circumstances, you wish to rebuild Qt from source, withQT_NAMESPACE
defined. Unless you (or someone else) rebuilds Qt from source, it's unlikely you'll ever need it.Of course, if you were creating code intended to be included in the Qt project, you would be required to use those the
QT_BEGIN_NAMESPACE
andQT_END_NAMESPACE
macros to allow users toQT_NAMESPACE
if they wish.See also:
- https://wiki.qt.io/Qt_In_Namespace
- https://stackoverflow.com/questions/3341350/is-it-important-to-declare-the-namespace-with-qt-begin-namespace-qt-end-names
Cheers.
-
@Galilio Wie @Paul-Colby richtig gesagt hat, ist dieses Makro interessant, wenn du forward-Deklarationen zu Qt-Klassen benutzt und Qt in einem namespace compiliert hast.
Wenn du deinen Quelltext an andere weitergibst, haben die damit max. Freiheit z.B. mehrere Qt-Versionen (in plugins oder DLLs) zu mischen.