QObject在QT中是所有类的基类,经过MOC处理后代码如下
之所以贴出这段代码,是因为很多流程追踪到最后一些关键性函数都是出自这个类
源码 4.8.6 MOC版本 63
1 /**************************************************************************** 2 ** Meta object code from reading C++ file 'qobject.h' 3 ** 4 ** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.6) 5 ** 6 ** WARNING! All changes made in this file will be lost! 7 *****************************************************************************/ 8 9 #include "qobject.h" 10 #if !defined(Q_MOC_OUTPUT_REVISION) 11 #error "The header file 'qobject.h' doesn't include <QObject>." 12 #elif Q_MOC_OUTPUT_REVISION != 63 13 #error "This file was generated using the moc from 4.8.6. It" 14 #error "cannot be used with the include files from this version of Qt." 15 #error "(The moc has changed too much.)" 16 #endif 17 18 QT_BEGIN_MOC_NAMESPACE 19 static const uint qt_meta_data_QObject[] = { 20 21 // content: 22 6, // revision 23 0, // classname 24 0, 0, // classinfo 25 4, 14, // methods 26 1, 34, // properties 27 0, 0, // enums/sets 28 2, 37, // constructors 29 0, // flags 30 2, // signalCount 31 32 // signals: signature, parameters, type, tag, flags 33 9, 8, 8, 8, 0x05, 34 29, 8, 8, 8, 0x25, 35 36 // slots: signature, parameters, type, tag, flags 37 41, 8, 8, 8, 0x0a, 38 55, 8, 8, 8, 0x08, 39 40 // properties: name, type, flags 41 90, 82, 0x0a095103, 42 43 // constructors: signature, parameters, type, tag, flags 44 108, 101, 8, 8, 0x0e, 45 126, 8, 8, 8, 0x2e, 46 47 0 // eod 48 }; 49 50 static const char qt_meta_stringdata_QObject[] = { 51 "QObject destroyed(QObject*) destroyed() " 52 "deleteLater() _q_reregisterTimers(void*) " 53 "QString objectName parent QObject(QObject*) " 54 "QObject() " 55 }; 56 57 void QObject::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) 58 { 59 if (_c == QMetaObject::CreateInstance) { 60 switch (_id) { 61 case 0: { QObject *_r = new QObject((*reinterpret_cast< QObject*(*)>(_a[1]))); 62 if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break; 63 case 1: { QObject *_r = new QObject(); 64 if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break; 65 } 66 } else if (_c == QMetaObject::InvokeMetaMethod) { 67 Q_ASSERT(staticMetaObject.cast(_o)); 68 QObject *_t = static_cast<QObject *>(_o); 69 switch (_id) { 70 case 0: _t->destroyed((*reinterpret_cast< QObject*(*)>(_a[1]))); break; 71 case 1: _t->destroyed(); break; 72 case 2: _t->deleteLater(); break; 73 case 3: _t->d_func()->_q_reregisterTimers((*reinterpret_cast< void*(*)>(_a[1]))); break; 74 default: ; 75 } 76 } 77 } 78 79 const QMetaObjectExtraData QObject::staticMetaObjectExtraData = { 80 0, qt_static_metacall 81 }; 82 83 const QMetaObject QObject::staticMetaObject = { 84 { 0, qt_meta_stringdata_QObject, 85 qt_meta_data_QObject, &staticMetaObjectExtraData } 86 }; 87 88 #ifdef Q_NO_DATA_RELOCATION 89 const QMetaObject &QObject::getStaticMetaObject() { return staticMetaObject; } 90 #endif //Q_NO_DATA_RELOCATION 91 92 const QMetaObject *QObject::metaObject() const 93 { 94 return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; 95 } 96 97 void *QObject::qt_metacast(const char *_clname) 98 { 99 if (!_clname) return 0; 100 if (!strcmp(_clname, qt_meta_stringdata_QObject)) 101 return static_cast<void*>(const_cast< QObject*>(this)); 102 return 0; 103 } 104 105 int QObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a) 106 { 107 if (_id < 0) 108 return _id; 109 if (_c == QMetaObject::InvokeMetaMethod) { 110 if (_id < 4) 111 qt_static_metacall(this, _c, _id, _a); 112 _id -= 4; 113 } 114 #ifndef QT_NO_PROPERTIES 115 else if (_c == QMetaObject::ReadProperty) { 116 void *_v = _a[0]; 117 switch (_id) { 118 case 0: *reinterpret_cast< QString*>(_v) = objectName(); break; 119 } 120 _id -= 1; 121 } else if (_c == QMetaObject::WriteProperty) { 122 void *_v = _a[0]; 123 switch (_id) { 124 case 0: setObjectName(*reinterpret_cast< QString*>(_v)); break; 125 } 126 _id -= 1; 127 } else if (_c == QMetaObject::ResetProperty) { 128 _id -= 1; 129 } else if (_c == QMetaObject::QueryPropertyDesignable) { 130 _id -= 1; 131 } else if (_c == QMetaObject::QueryPropertyScriptable) { 132 _id -= 1; 133 } else if (_c == QMetaObject::QueryPropertyStored) { 134 _id -= 1; 135 } else if (_c == QMetaObject::QueryPropertyEditable) { 136 _id -= 1; 137 } else if (_c == QMetaObject::QueryPropertyUser) { 138 _id -= 1; 139 } 140 #endif // QT_NO_PROPERTIES 141 return _id; 142 } 143 144 // SIGNAL 0 145 void QObject::destroyed(QObject * _t1) 146 { 147 void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) }; 148 QMetaObject::activate(this, &staticMetaObject, 0, _a); 149 } 150 QT_END_MOC_NAMESPACE
仅供参考,做一些深层次的分析