Qtmeta-object system, which isMeta Object System(MoS), provides a well-known signal and slot mechanism for inter-object information transfer, runtime type information and dynamic property system.
MoS based on three pieces of magic:
one is qobject qt The base class of objects, can be used very well mos Span style= "Font-family:wenquanyi Micro Hei" >
Second, Q_object macros, in class Private partial declarations, for activating MoS Properties , such as dynamic properties, signals, and slots.
The third is the Meta object compiler, which isMeta Object compiler(MOC), forQobjectderived classes provide the necessary code to implement theMoSfeature. For exampleExample.hstated in theExampleclass, inherited fromQobjectclass and uses theQ_objectmacro, thenMOCwill find a way to useQ_objectThe macro declares that thisExampleclass, and then generates aMoc_example.cppdocument that records the relevantMoScode.
MoS In addition to the core of the signal and groove, there are some practical things:
1 , qobject::metaobject () qmetaobject pointer ;
qobject::staticmetaobject < Span style= "font-size:14px" > qmetaobject
2 , qobject::inherits ()
3 , qobject::tr () Span style= "Font-family:wenquanyi Micro Hei" > qt language internationalization, return type is qstring
4 , qobject::p roperty ()/ SetProperty () , dynamically get Modify property values.
5 , qmetaobject::classname () runtime return class name , the return type is char*
6 , qmetaobject::newinstance () , a new instance is constructed.
7,qobject_cast (), dynamic type conversions, similar to standardC + +of thedynamic_cast (), the difference is that it doesn't needRTTI(run Time type information) and is not limited by the dynamic library.
What is a QT meta-object system