CopperSpice Overview
How Qt used Moc

Moc is typically used with an input file containing class declarations similar to the following:

class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject *parent = 0);
~MyClass();
signals:
void mySignal();
public slots:
void mySlot();
};


In addition to signals and slots, moc also implements object properties. The Q_PROPERTY() macro declares an object property while Q_ENUMS() declare a list of enumeration types within the class, which is usable inside the Property System.

class MyClass : public QObject
{
Q_OBJECT
Q_PROPERTY(Priority priority READ priority WRITE setPriority)
Q_ENUMS(Priority)
public:
enum Priority { High, Low, VeryHigh, VeryLow };
MyClass(QObject *parent = 0);
~MyClass();
void setPriority(Priority priority) { m_priority = priority; }
Priority priority() const { return m_priority; }
private:
Priority m_priority;
};


The Q_FLAGS() macro declares enums that are to be used as flags. Q_CLASSINFO() allows an application to attach additional name/value pairs to the class's meta-object.

class MyClass : public QObject
{
Q_OBJECT
Q_CLASSINFO("Author", "Oscar Peterson")
Q_CLASSINFO("Status", "Active")
public:
MyClass(QObject *parent = 0);
~MyClass();
};


If this class declaration is located in the file myclass.h then the moc output will be put in a file called moc_myclass.cpp. This cpp file is compiled resulting in an object file named moc_myclass.o. The object file must be included in the final linking phase of your application.