Inside QT series (6): Meta Object compiler-meta object Compiler (MOC)

Source: Internet
Author: User

The metabase compiler is used to process C ++ extensions of QT. MoC analyzes the C ++ source file. If it finds that a header file contains the q_object macro definition, then, another c ++ source file is generated dynamically. The new source file contains the implementation of q_object.Code, The new C ++ source file will also be compiled,LinkTo the binary code of this class, because it is also a complete Part of this class. Generally, the new C ++ source file will be added to the previous C ++ source file name with MOC _ as the file name of the new file.

If you use the qmake tool to generate makefile files, all compilation rules that require MoC will be automatically included in the MAKEFILE file.ProgramPersonnel do not need to use MOC directly

Besides ProcessingSignalIn addition to the slot, MoC also processes the property information. The q_property () macro defines the property information of the class, while the q_enums () macro defines the enumeration type list in the class. The q_flags () macro is defined in the flag Enumeration type list of a class. The q_classinfo () macro allows you to insert name/value pairs in the meta information of a class.

The files generated by MOC must be compiled and linked, just like the other C ++ file you write yourself. Otherwise, the link will fail.

Code example:

Class myclass: Public qobject
{
Q_object
Q_property (Priority priority read priority write setpriority)
Q_enums (priority)
Q_classinfo ("author", "Oscar Peterson ")
Q_classinfo ("status", "active ")

Public:
Enum priority {high, low, veryhigh, verylow };

Myclass (qobject * parent = 0 );
Virtual ~ Myclass ();

Void setpriority (Priority priority );
Priority priority () const;
};

 

========================================================== ====================================
Statement:
Inside QT series columnArticleIs (http://www.qkevin.com) original technical article.
This series of columns can be reproduced at will, but the statement and original address of each article must be kept.
The Copyright reserved by the author shall not be used for any commercial purposes without the consent of the author

"Inside QT series" column index: http://www.qkevin.com/qt
original address: http://www.qkevin.com/archives/68

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.