在Qt下,从QObject派生的类都会生成moc_文件。
1. 比如现在有2个文件,qmyobject.h和qmyobject.cpp,它里面有一个类QMyObject,记为版本A
classQMyObject :publicQObject
{
Q_OBJECT
public:
QMyObject(QObject *parent);
~QMyObject();
};
然后我们给其添加一个信号和一个槽函数,即修改后的qmyobject.h的内容如下,记为版本B。
classQMyObject :publicQObject
{
Q_OBJECT
public:
QMyObject(QObject *parent);
~QMyObject();
signals:
voidsignalFunc(double);
protectedslots:
voidslotFunc(double);
};
下面给出2个这2个版本的moc文件
未添加signal/slot
添加了signal/slot
/****************************************************************************
** Meta object code from reading C++ file 'qmyobject.h'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.2.1)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
#include "../../qmyobject.h"
#include
#include
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'qmyobject.h' doesn't include ."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.2.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
QT_BEGIN_MOC_NAMESPACE
structqt_meta_stringdata_QMyObject_t {
QByteArrayData data[1];
charstringdata[11];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSE