6. Qt 信号与信号槽(3)-QMetaObject
生活随笔
收集整理的這篇文章主要介紹了
6. Qt 信号与信号槽(3)-QMetaObject
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
QMetaObject包含了QObject的元數據,也就是QObject信息的一些描述信息:除了類型信息外, signal&slot信息,Property等。數據都保存在d指針里面( QMetaObject.h 最后有聲明d指針變量)。
QMetaObject.h
struct Q_CORE_EXPORT QMetaObject {class Connection;const char *className() const;const QMetaObject *superClass() const;bool inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT;QObject *cast(QObject *obj) const;const QObject *cast(const QObject *obj) const;#if !defined(QT_NO_TRANSLATION) || defined(Q_CLANG_QDOC)QString tr(const char *s, const char *c, int n = -1) const; #endif // QT_NO_TRANSLATIONint methodOffset() const;int enumeratorOffset() const;int propertyOffset() const;int classInfoOffset() const;int constructorCount() const;int methodCount() const;int enumeratorCount() const;int propertyCount() const;int classInfoCount() const;int indexOfConstructor(const char *constructor) const;int indexOfMethod(const char *method) const;int indexOfSignal(const char *signal) const;int indexOfSlot(const char *slot) const;int indexOfEnumerator(const char *name) const;int indexOfProperty(const char *name) const;int indexOfClassInfo(const char *name) const;QMetaMethod constructor(int index) const;QMetaMethod method(int index) const;QMetaEnum enumerator(int index) const;QMetaProperty property(int index) const;QMetaClassInfo classInfo(int index) const;QMetaProperty userProperty() const;static bool checkConnectArgs(const char *signal, const char *method); // internal index-based connectstatic Connection connect(const QObject *sender, int signal_index,const QObject *receiver, int method_index,int type = 0, int *types = nullptr);// internal index-based disconnectstatic bool disconnect(const QObject *sender, int signal_index,const QObject *receiver, int method_index);static void connectSlotsByName(QObject *o);// internal index-based signal activationstatic void activate(QObject *sender, int signal_index, void **argv);static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);static inline bool invokeMethod(QObject *obj, const char *member,Qt::ConnectionType type,QGenericArgument val0 = QGenericArgument(nullptr),QGenericArgument val1 = QGenericArgument(), // invokeMethod() for member function pointertemplate <typename Func>static typename std::enable_if<QtPrivate::FunctionPointer<Func>::IsPointerToMemberFunction&& !std::is_convertible<Func, const char*>::value&& QtPrivate::FunctionPointer<Func>::ArgumentCount == 0, bool>::typeinvokeMethod(typename QtPrivate::FunctionPointer<Func>::Object *object,Func function,Qt::ConnectionType type = Qt::AutoConnection,typename QtPrivate::FunctionPointer<Func>::ReturnType *ret = nullptr){return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs<Func>(function), type, ret);} #endifQObject *newInstance(QGenericArgument val0 = QGenericArgument(nullptr),enum Call {InvokeMetaMethod,ReadProperty,WriteProperty,ResetProperty,QueryPropertyDesignable,QueryPropertyScriptable,QueryPropertyStored,QueryPropertyEditable,QueryPropertyUser,CreateInstance,IndexOfMethod,RegisterPropertyMetaType,RegisterMethodArgumentMetaType};int static_metacall(Call, int, void **) const;static int metacall(QObject *, Call, int, void **);struct { // private dataconst QMetaObject *superdata;//父類的staticMetaObject指針const QByteArrayData *stringdata;// 字符串數組,保存類的 類名,槽函數名 信號函數名等 字符串信息。const uint *data;//該數組是個預定義的復合數據結構,由QMetaObjectPrivate 類提供管理,保存了類的基本信息,和一些索引值typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);StaticMetacallFunction static_metacall;const QMetaObject * const *relatedMetaObjects;void *extradata; //reserved for future use} d;private:static bool invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret); };總結
以上是生活随笔為你收集整理的6. Qt 信号与信号槽(3)-QMetaObject的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 6. Qt 信号与信号槽(1)
- 下一篇: 6. Qt 信号与信号槽(4)-QMet