What is a QT meta-object system

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.