Important: Please read the Qt Code of Conduct -

Wofür der Macro "QT_BEGIN_NAMESPACE"

  • Hallo Zusammen,

    bei Qt5 ist mir aufgefallen die Benutzung von dieses Macro QT_BEGIN_NAMESPACE.

    class QAction;
    class QCheckBox;
    class QComboBox;
    class QGroupBox;
    class QLabel;
    class QLineEdit;
    class QMenu;
    class QPushButton;
    class QSpinBox;
    class QTextEdit;
    //! [0]
    class Window : public QDialog
        void setVisible(bool visible) Q_DECL_OVERRIDE;
        void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
    private slots:
        void setIcon(int index);
        void iconActivated(QSystemTrayIcon::ActivationReason reason);
        void showMessage();
        void messageClicked();
        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?


  • 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 (ie QT_NAMESPACE is empty, and QT_BEGIN_NAMESPACE does nothing). However, in some circumstances, you wish to rebuild Qt from source, with QT_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 and QT_END_NAMESPACE macros to allow users to QT_NAMESPACE if they wish.

    See also:


  • Lifetime Qt Champion

    @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.

Log in to reply