QObject在QT中是所有类的基类,经过MOC处理后代码如下
之所以贴出这段代码,是因为很多流程追踪到最后一些关键性函数都是出自这个类
源码 4.8.6 MOC版本 63
/****************************************************************************
** Meta object code from reading C++ file 'qobject.h'
**
** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.6)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/ #include "qobject.h"
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'qobject.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 63
#error "This file was generated using the moc from 4.8.6. 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
static const uint qt_meta_data_QObject[] = { // content:
, // revision
, // classname
, , // classinfo
, , // methods
, , // properties
, , // enums/sets
, , // constructors
, // flags
, // signalCount // signals: signature, parameters, type, tag, flags
, , , , 0x05,
, , , , 0x25, // slots: signature, parameters, type, tag, flags
, , , , 0x0a,
, , , , 0x08, // properties: name, type, flags
, , 0x0a095103, // constructors: signature, parameters, type, tag, flags
, , , , 0x0e,
, , , , 0x2e, // eod
}; static const char qt_meta_stringdata_QObject[] = {
"QObject\0\0destroyed(QObject*)\0destroyed()\0"
"deleteLater()\0_q_reregisterTimers(void*)\0"
"QString\0objectName\0parent\0QObject(QObject*)\0"
"QObject()\0"
}; void QObject::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::CreateInstance) {
switch (_id) {
case : { QObject *_r = new QObject((*reinterpret_cast< QObject*(*)>(_a[])));
if (_a[]) *reinterpret_cast<QObject**>(_a[]) = _r; } break;
case : { QObject *_r = new QObject();
if (_a[]) *reinterpret_cast<QObject**>(_a[]) = _r; } break;
}
} else if (_c == QMetaObject::InvokeMetaMethod) {
Q_ASSERT(staticMetaObject.cast(_o));
QObject *_t = static_cast<QObject *>(_o);
switch (_id) {
case : _t->destroyed((*reinterpret_cast< QObject*(*)>(_a[]))); break;
case : _t->destroyed(); break;
case : _t->deleteLater(); break;
case : _t->d_func()->_q_reregisterTimers((*reinterpret_cast< void*(*)>(_a[]))); break;
default: ;
}
}
} const QMetaObjectExtraData QObject::staticMetaObjectExtraData = {
, qt_static_metacall
}; const QMetaObject QObject::staticMetaObject = {
{ , qt_meta_stringdata_QObject,
qt_meta_data_QObject, &staticMetaObjectExtraData }
}; #ifdef Q_NO_DATA_RELOCATION
const QMetaObject &QObject::getStaticMetaObject() { return staticMetaObject; }
#endif //Q_NO_DATA_RELOCATION const QMetaObject *QObject::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
} void *QObject::qt_metacast(const char *_clname)
{
if (!_clname) return ;
if (!strcmp(_clname, qt_meta_stringdata_QObject))
return static_cast<void*>(const_cast< QObject*>(this));
return ;
} int QObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
if (_id < )
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < )
qt_static_metacall(this, _c, _id, _a);
_id -= ;
}
#ifndef QT_NO_PROPERTIES
else if (_c == QMetaObject::ReadProperty) {
void *_v = _a[];
switch (_id) {
case : *reinterpret_cast< QString*>(_v) = objectName(); break;
}
_id -= ;
} else if (_c == QMetaObject::WriteProperty) {
void *_v = _a[];
switch (_id) {
case : setObjectName(*reinterpret_cast< QString*>(_v)); break;
}
_id -= ;
} else if (_c == QMetaObject::ResetProperty) {
_id -= ;
} else if (_c == QMetaObject::QueryPropertyDesignable) {
_id -= ;
} else if (_c == QMetaObject::QueryPropertyScriptable) {
_id -= ;
} else if (_c == QMetaObject::QueryPropertyStored) {
_id -= ;
} else if (_c == QMetaObject::QueryPropertyEditable) {
_id -= ;
} else if (_c == QMetaObject::QueryPropertyUser) {
_id -= ;
}
#endif // QT_NO_PROPERTIES
return _id;
} // SIGNAL 0
void QObject::destroyed(QObject * _t1)
{
void *_a[] = { , const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, , _a);
}
QT_END_MOC_NAMESPACE
仅供参考,做一些深层次的分析