Q_OBJECT类

来源:互联网 发布:战地1枪械数据 编辑:程序博客网 时间:2024/06/07 13:13
接触QT时只知道要想在类中使用QT的signal-slots机制的时候,必须在类声明开始的地方加上Q_OBJECT宏。
QT的帮助文档是这样描述Q_OBJECT宏的:
The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.

#include <QObject>


class Counter : public QObject

{

    Q_OBJECT

public:

    Counter() { m_value = 0; }

    int value() const { return m_value; }

 

public slots:

    void setValue(int value);

 

signals:

    void valueChanged(int newValue);

 

private:

    int m_value;

};

那么Q_OBJECT宏到底做了哪些工作呢?什么是QT的元对象系统呢?

原创粉丝点击